Skip to content

Commit

Permalink
Merge branch '2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Jul 8, 2014
2 parents 40be52d + 1e03987 commit 79cb04d
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"laravel/framework": "4.3.*"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"behat/behat": "2.5.*",
"phpunit/phpunit": "~4"
},
Expand Down
6 changes: 4 additions & 2 deletions docs/changes.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
title: Testbench Change Log

---

## Version 2.2 {#v2-2}

### v2.2.1@dev {#v2-2-1}
### v2.2.1 {#v2-2-1}

* Add experimental support for Behat when testing packages without a server
* Add support for Behat when testing packages as an alternative to PHPUnit.
* Remove requirement to use phpseclib fork since v0.3.7 already provides compatibility to Laravel 4 workbench.

### v2.2.0 {#v2-2-0}

Expand Down
76 changes: 76 additions & 0 deletions src/Testbench/Testing/UnitAssertionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php namespace Orchestra\Testbench\Testing;

use Illuminate\Support\Fluent;
use Illuminate\View\View;
use Mockery as m;

trait UnitAssertionTrait
{
public function testAssertResponseOkMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$client->shouldReceive('getResponse')->once()->andReturnSelf()
->shouldReceive('getStatusCode')->once()->andReturn(200)
->shouldReceive('isOk')->once()->andReturn(true);

$this->assertResponseOk();
}

public function testAssertResponseStatusMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$client->shouldReceive('getResponse')->once()->andReturnSelf()
->shouldReceive('getStatusCode')->once()->andReturn(400);

$this->assertResponseStatus(400);
}

public function testAssertViewHasMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');
$view = new View(m::mock('\Illuminate\View\Factory'), m::mock('\Illuminate\View\Engines\EngineInterface'), 'hello', '/var/laravel/views', [
'foo' => 'bar',
'hello' => 'world',
]);

$response = new Fluent([
'original' => $view,
]);

$client->shouldReceive('getResponse')->once()->andReturn($response);

$this->assertViewHas('foo');
$this->assertViewHas('hello', 'world');
}

public function testAssertViewHasAllMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');
$view = new View(m::mock('\Illuminate\View\Factory'), m::mock('\Illuminate\View\Engines\EngineInterface'), 'hello', '/var/laravel/views', [
'foo' => 'bar',
'bar' => 'foo',
]);
$response = new Fluent([
'original' => $view,
]);

$client->shouldReceive('getResponse')->once()->andReturn($response);

$this->assertViewHas(['foo', 'bar', 'foo' => 'bar']);
}

public function testAssertViewMissingMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');
$view = new View(m::mock('\Illuminate\View\Factory'), m::mock('\Illuminate\View\Engines\EngineInterface'), 'hello', '/var/laravel/views', []);
$response = new Fluent([
'original' => $view,
]);

$client->shouldReceive('getResponse')->once()->andReturn($response);

$this->assertViewMissing('foo');
}
}
180 changes: 180 additions & 0 deletions tests/Traits/ApplicationClientTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php namespace Orchestra\Testbench\TestCase\Traits;

use Illuminate\Container\Container;
use Mockery as m;
use Orchestra\Testbench\Traits\ApplicationClientTrait;

class ApplicationClientTraitTest extends \PHPUnit_Framework_TestCase
{
use ApplicationClientTrait;

/**
* Teardown the test environment.
*/
public function tearDown()
{
unset($this->app);
unset($this->client);

m::close();
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::call()
* method.
*
* @test
*/
public function testCallMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$client->shouldReceive('request')->once()->with('GET', 'foo')->andReturnSelf()
->shouldReceive('getResponse')->once()->andReturn('foobar');

$this->assertEquals('foobar', $this->call('GET', 'foo'));
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::callSecure()
* method.
*
* @test
*/
public function testCallSecureMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$client->shouldReceive('request')->once()->with('GET', 'https://localhost/foo')->andReturnSelf()
->shouldReceive('getResponse')->once()->andReturn('foobar');

$this->assertEquals('foobar', $this->callSecure('GET', 'foo'));
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::action()
* method.
*
* @test
*/
public function testActionMethod()
{
$this->app = new Container;

$this->app['url'] = $url = m::mock('\Illuminate\Routing\UrlGenerator[route]', [
m::mock('\Illuminate\Routing\RouteCollection'),
m::mock('\Illuminate\Http\Request'),
]);

$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$url->shouldReceive('route')->once()->with('foo.show', [])->andReturn('http://localhost/foo');

$client->shouldReceive('request')->once()->with('GET', 'http://localhost/foo', [], [], [], null, true)->andReturnSelf()
->shouldReceive('getResponse')->once()->andReturn('foobar');

$this->assertEquals('foobar', $this->route('GET', 'foo.show'));
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::be()
* method.
*
* @test
*/
public function testBeMethod()
{
$this->app = new Container;

$this->app['auth'] = $auth = m::mock('\Illuminate\Auth\AuthManager[driver]', [$this->app]);

$user = m::mock('\Illuminate\Auth\UserInterface');
$driver = 'eloquent';

$auth->shouldReceive('driver')->once()->with($driver)->andReturnSelf()
->shouldReceive('setUser')->once()->with($user)->andReturnNull();

$this->assertNull($this->be($user, $driver));
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::seed()
* method.
*
* @test
*/
public function testSeedMethod()
{
$this->app = new Container;

$this->app['artisan'] = $artisan = m::mock('\Illuminate\Console\Application');

$class = 'UserSeeder';

$artisan->shouldReceive('call')->once()->with('db:seed', ['--class' => $class])->andReturnNull();

$this->assertNull($this->seed($class));
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::startSession()
* method.
*
* @test
*/
public function testStartSessionMethod()
{
$this->app = new Container;

$this->app['session'] = $session = m::mock('\Illuminate\Session\Store');

$session->shouldReceive('isStarted')->once()->andReturn(false)
->shouldReceive('start')->once()->andReturnNull();

$this->assertNull($this->startSession());
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::flushSession()
* method.
*
* @test
*/
public function testFlushSessionMethod()
{
$this->app = new Container;

$this->app['session'] = $session = m::mock('\Illuminate\Session\Store');

$session->shouldReceive('isStarted')->once()->andReturn(true)
->shouldReceive('flush')->once()->andReturnNull();

$this->assertNull($this->flushSession());
}

/**
* Test Orchestra\Testbench\Traits\ApplicationClientTrait::session()
* method.
*
* @test
*/
public function testSessionMethod()
{
$this->app = new Container;

$this->app['session'] = $session = m::mock('\Illuminate\Session\Store');

$data = [
['foo' => 'bar'],
['hello' => 'world'],
];

$session->shouldReceive('isStarted')->once()->andReturn(true);

foreach ($data as $key => $value) {
$session->shouldReceive('put')->once()->with($key, $value)->andReturnNull();
}

$this->assertNull($this->session($data));
}
}
10 changes: 10 additions & 0 deletions tests/Traits/BehatPHPAssertionsTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php namespace Orchestra\Testbench\TestCase\Traits;

use Mockery as m;
use Orchestra\Testbench\Testing\UnitAssertionTrait;
use Orchestra\Testbench\Traits\BehatPHPUnitAssertionsTrait;

class BehatPHPAssertionsTraitTest extends \PHPUnit_Framework_TestCase
{
use BehatPHPUnitAssertionsTrait, UnitAssertionTrait;
}
10 changes: 10 additions & 0 deletions tests/Traits/PHPUnitAssertionsTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php namespace Orchestra\Testbench\TestCase\Traits;

use Mockery as m;
use Orchestra\Testbench\Testing\UnitAssertionTrait;
use Orchestra\Testbench\Traits\PHPUnitAssertionsTrait;

class PHPUnitAssertionsTraitTest extends \PHPUnit_Framework_TestCase
{
use PHPUnitAssertionsTrait, UnitAssertionTrait;
}

0 comments on commit 79cb04d

Please sign in to comment.