-
-
Save anonymous/1747807767260682e4a9 to your computer and use it in GitHub Desktop.
Simple Factory Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Pattern\SimpleFactory; | |
use PHPUnit_Framework_TestCase; | |
class CarFactoryTest extends PHPUnit_Framework_TestCase { | |
private $factory; | |
public function setUp() | |
{ | |
$this->factory = new CarFactory(); | |
} | |
/** | |
* @covers Pattern\SimpleFactory\CarFactory::make | |
* @expectedException \InvalidArgumentException | |
* @expectedExceptionMessage You tried to make a nonexistent car | |
*/ | |
public function testShouldThrowAnExceptionWhenTryingToMakeANonexistentCar() | |
{ | |
$this->factory->make('nonexistent'); | |
} | |
/** | |
* @covers Pattern\SimpleFactory\CarFactory::make | |
* @uses Pattern\SimpleFactory\Car | |
*/ | |
public function testShouldMakeAndReturnTheExpectedCar() | |
{ | |
$car = $this->factory->make('galaxy'); | |
$this->assertInstanceOf(Car::class, $car); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Pattern\SimpleFactory; | |
use PHPUnit_Framework_TestCase; | |
class CarStoreTest extends PHPUnit_Framework_TestCase { | |
/** | |
* @covers Pattern\SimpleFactory\CarStore::__construct | |
* @covers Pattern\SimpleFactory\CarStore::order | |
* @uses Pattern\SimpleFactory\CarFactory | |
*/ | |
public function testShouldCallFactoriesMakeMethod() | |
{ | |
$factory = $this->getMock(CarFactory::class); | |
$factory->expects($this->once())->method('make')->with('galaxy'); | |
$store = new CarStore($factory); | |
$store->order('galaxy'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment