Skip to content

Commit b72aeb0

Browse files
committed
Use zalas/phpunit-doubles to simplfiy test double creation
1 parent 35a8fbc commit b72aeb0

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"symfony/dependency-injection": "^3.4 || ^4.0",
1414
"symfony/http-kernel": "^3.4 || ^4.0",
1515
"zalas/phpunit-globals": "^1.0",
16-
"symfony/framework-bundle": "^3.4||^4.0"
16+
"symfony/framework-bundle": "^3.4||^4.0",
17+
"zalas/phpunit-doubles": "^1.2"
1718
},
1819
"autoload": {
1920
"psr-4": {

tests/Symfony/Compiler/Discovery/PropertyDiscoveryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
use Zalas\Injector\Service\Extractor;
1616
use Zalas\Injector\Service\ExtractorFactory;
1717
use Zalas\Injector\Service\Property;
18+
use Zalas\PHPUnit\Doubles\TestCase\TestDoubles;
1819

1920
class PropertyDiscoveryTest extends TestCase
2021
{
22+
use TestDoubles;
23+
2124
/**
2225
* @var PropertyDiscovery
2326
*/
@@ -39,10 +42,6 @@ class PropertyDiscoveryTest extends TestCase
3942

4043
protected function setUp()
4144
{
42-
$this->extractorFactory = $this->prophesize(ExtractorFactory::class);
43-
$this->extractor = $this->prophesize(Extractor::class);
44-
$this->classFinder = $this->prophesize(ClassFinder::class);
45-
4645
$this->discovery = new PropertyDiscovery($this->classFinder->reveal(), $this->extractorFactory->reveal());
4746

4847
$this->classFinder->findImplementations(Argument::any())->willReturn([]);

tests/Symfony/Compiler/ExposeServicesForTestsPassTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
use Zalas\Injector\PHPUnit\Tests\Symfony\Compiler\Fixtures\TestCase1;
1919
use Zalas\Injector\PHPUnit\Tests\Symfony\Compiler\Fixtures\TestCase2;
2020
use Zalas\Injector\Service\Property;
21+
use Zalas\PHPUnit\Doubles\TestCase\TestDoubles;
2122

2223
class ExposeServicesForTestsPassTest extends TestCase
2324
{
25+
use TestDoubles;
26+
2427
/**
2528
* @var ExposeServicesForTestsPass
2629
*/
@@ -33,7 +36,6 @@ class ExposeServicesForTestsPassTest extends TestCase
3336

3437
protected function setUp()
3538
{
36-
$this->discovery = $this->prophesize(PropertyDiscovery::class);
3739
$this->pass = new ExposeServicesForTestsPass($this->discovery->reveal());
3840
}
3941

tests/TestListener/TestCaseContainerFactoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
use Zalas\Injector\PHPUnit\TestCase\ServiceContainerTestCase;
1010
use Zalas\Injector\PHPUnit\TestListener\TestCaseContainerFactory;
1111
use Zalas\Injector\Service\ContainerFactory;
12+
use Zalas\PHPUnit\Doubles\TestCase\TestDoubles;
1213

1314
class TestCaseContainerFactoryTest extends TestCase
1415
{
16+
use TestDoubles;
17+
1518
/**
1619
* @var TestCaseContainerFactory
1720
*/
1821
private $factory;
1922

2023
/**
21-
* @var ContainerInterface
24+
* @var ContainerInterface|ObjectProphecy
2225
*/
2326
private $container;
2427

@@ -29,9 +32,6 @@ class TestCaseContainerFactoryTest extends TestCase
2932

3033
protected function setUp()
3134
{
32-
$this->container = $this->prophesize(ContainerInterface::class)->reveal();
33-
$this->testCase = $this->prophesize(ServiceContainerTestCase::class);
34-
3535
$this->factory = new TestCaseContainerFactory($this->testCase->reveal());
3636
}
3737

@@ -46,6 +46,6 @@ public function test_it_uses_the_test_case_to_create_a_container()
4646

4747
$createdContainer = $this->factory->create();
4848

49-
$this->assertSame($this->container, $createdContainer);
49+
$this->assertSame($this->container->reveal(), $createdContainer);
5050
}
5151
}

0 commit comments

Comments
 (0)