Skip to content

Commit c09f45e

Browse files
committed
Removed usage of deprecated getMock()
1 parent 1905433 commit c09f45e

File tree

3 files changed

+63
-66
lines changed

3 files changed

+63
-66
lines changed

tests/Functional/BaseTestCaseTest.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,36 @@
1515

1616
class BaseTestCaseTest extends \PHPUnit_Framework_TestCase
1717
{
18-
public function setUp()
19-
{
20-
$this->testCase = new TestTestCase();
21-
22-
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
18+
private $container;
19+
private $kernel;
20+
private $testCase;
21+
private $client;
2322

24-
$me = $this;
23+
protected function setUp()
24+
{
25+
$this->container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
2526
$this->container->expects($this->any())
2627
->method('get')
27-
->will($this->returnCallback(function ($name) use ($me) {
28-
$dic = array(
29-
'test.client' => $me->client,
30-
);
28+
->will($this->returnCallback(function ($name) {
29+
$dic = [
30+
'test.client' => $this->client,
31+
];
3132

3233
return $dic[$name];
3334
}));
3435

35-
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
36-
37-
$this->testCase->setKernel($this->kernel);
38-
36+
$this->kernel = $this->createMock('Symfony\Component\HttpKernel\KernelInterface');
3937
$this->kernel->expects($this->any())
4038
->method('getContainer')
41-
->will($this->returnValue($this->container));
39+
->willReturn($this->container);
4240

43-
$this->client = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Client')
44-
->disableOriginalConstructor()
45-
->getMock();
41+
$this->testCase = new TestTestCase();
42+
$this->testCase->setKernel($this->kernel);
4643

44+
$this->client = $this->createMock('Symfony\Bundle\FrameworkBundle\Client');
4745
$this->client->expects($this->any())
4846
->method('getContainer')
49-
->will($this->returnValue($this->container));
47+
->willReturn($this->container);
5048
}
5149

5250
public function testGetContainer()
@@ -56,12 +54,12 @@ public function testGetContainer()
5654

5755
public function provideTestDb()
5856
{
59-
return array(
60-
array('PHPCR', 'PHPCR'),
61-
array('Phpcr', 'PHPCR'),
62-
array('ORM', 'ORM'),
63-
array('foobar', null),
64-
);
57+
return [
58+
['PHPCR', 'PHPCR'],
59+
['Phpcr', 'PHPCR'],
60+
['ORM', 'ORM'],
61+
['foobar', null],
62+
];
6563
}
6664

6765
/**

tests/HttpKernel/TestKernelTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
class TestKernelTest extends \PHPUnit_Framework_TestCase
2121
{
22-
public function setUp()
22+
private $kernel;
23+
private $mockBundle;
24+
25+
protected function setUp()
2326
{
24-
$this->kernel = $this->getMockBuilder(
25-
'Symfony\Cmf\Component\Testing\HttpKernel\TestKernel'
26-
)->setConstructorArgs(array('test', true))->getMockForAbstractClass();
27-
$this->mockBundle = $this->getMock(
28-
'Symfony\Component\HttpKernel\Bundle\BundleInterface'
29-
);
27+
$this->kernel = $this->getMockBuilder('Symfony\Cmf\Component\Testing\HttpKernel\TestKernel')
28+
->setConstructorArgs(array('test', true))
29+
->getMockForAbstractClass();
30+
31+
$this->mockBundle = $this->createMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
3032
}
3133

3234
/**
@@ -37,7 +39,7 @@ public function testBundleSetRequire(array $bundleSets, array $expectedBundles)
3739
$this->kernel->requireBundleSets($bundleSets);
3840
$bundles = array_keys($this->kernel->registerBundles());
3941

40-
$this->assertArraySubset($expectedBundles, $bundles);
42+
$this->assertArraySubset($expectedBundles, $bundles);
4143
}
4244

4345
public function bundleSetProvider()

tests/Phpunit/DatabaseTestListenerTest.php

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@ class DatabaseTestListenerTest extends \PHPUnit_Framework_TestCase
1919
private $processBuilder;
2020
private static $i;
2121

22-
public function setUp()
22+
protected function setUp()
2323
{
2424
$this->listener = new DatabaseTestListener($this->getProcessBuilder());
2525
self::$i = 0;
2626
}
2727

2828
public function testPhpcrTestSuite()
2929
{
30-
$suite = $this->getMock('PHPUnit_Framework_TestSuite');
30+
$suite = $this->createMock('PHPUnit_Framework_TestSuite');
3131
$suite->expects($this->any())
3232
->method('getName')
33-
->will($this->returnValue('phpcr'));
33+
->willReturn('phpcr');
3434

35-
$this->assertProcessExecuted(array('doctrine:phpcr:init:dbal', '--drop', '--force'));
36-
$this->assertProcessExecuted(array('doctrine:phpcr:repository:init'));
35+
$this->assertProcessExecuted(['doctrine:phpcr:init:dbal', '--drop', '--force']);
36+
$this->assertProcessExecuted(['doctrine:phpcr:repository:init']);
3737

3838
ob_start();
3939
$this->listener->startTestSuite($suite);
4040

41-
$this->assertEquals(PHP_EOL.PHP_EOL.'[PHPCR]'.PHP_EOL, ob_get_clean());
41+
$this->assertContains('[PHPCR]', ob_get_clean());
4242
}
4343

4444
public function testFallsBackToOldInitDbalCommand()
4545
{
46-
$suite = $this->getMock('PHPUnit_Framework_TestSuite');
46+
$suite = $this->createMock('PHPUnit_Framework_TestSuite');
4747
$suite->expects($this->any())
4848
->method('getName')
49-
->will($this->returnValue('phpcr'));
49+
->willReturn('phpcr');
5050

51-
$this->assertProcessExecuted(array('doctrine:phpcr:init:dbal', '--drop', '--force'), false);
52-
$this->assertProcessExecuted(array('doctrine:phpcr:init:dbal', '--drop'), true);
53-
$this->assertProcessExecuted(array('doctrine:phpcr:repository:init'));
51+
$this->assertProcessExecuted(['doctrine:phpcr:init:dbal', '--drop', '--force'], false);
52+
$this->assertProcessExecuted(['doctrine:phpcr:init:dbal', '--drop'], true);
53+
$this->assertProcessExecuted(['doctrine:phpcr:repository:init']);
5454

5555
ob_start();
5656
$this->listener->startTestSuite($suite);
@@ -59,67 +59,64 @@ public function testFallsBackToOldInitDbalCommand()
5959

6060
public function testOrmTestSuite()
6161
{
62-
$suite = $this->getMock('PHPUnit_Framework_TestSuite');
62+
$suite = $this->createMock('PHPUnit_Framework_TestSuite');
6363
$suite->expects($this->any())
6464
->method('getName')
65-
->will($this->returnValue('orm'));
65+
->willReturn('orm');
6666

67-
$this->assertProcessExecuted(array('doctrine:schema:drop', '--env=orm', '--force'));
68-
$this->assertProcessExecuted(array('doctrine:database:create', '--env=orm'));
69-
$this->assertProcessExecuted(array('doctrine:schema:create', '--env=orm'));
67+
$this->assertProcessExecuted(['doctrine:schema:drop', '--env=orm', '--force']);
68+
$this->assertProcessExecuted(['doctrine:database:create', '--env=orm']);
69+
$this->assertProcessExecuted(['doctrine:schema:create', '--env=orm']);
7070

7171
ob_start();
7272
$this->listener->startTestSuite($suite);
7373

74-
$this->assertEquals(PHP_EOL.PHP_EOL.'[ORM]'.PHP_EOL, ob_get_clean());
74+
$this->assertContains('[ORM]', ob_get_clean());
7575
}
7676

7777
public function testUnknownTestSuite()
7878
{
79-
$suite = $this->getMock('PHPUnit_Framework_TestSuite');
79+
$suite = $this->createMock('PHPUnit_Framework_TestSuite');
8080
$suite->expects($this->any())
8181
->method('getName')
82-
->will($this->returnValue('not orm or phpcr tests'));
82+
->willReturn('not orm or phpcr tests');
8383

84-
$this->getProcessBuilder()
85-
->expects($this->never())
86-
->method('setArguments');
84+
$this->getProcessBuilder()->expects($this->never())->method('setArguments');
8785

8886
ob_start();
8987
$this->listener->startTestSuite($suite);
9088

91-
$this->assertEquals(PHP_EOL.PHP_EOL.'[not orm or phpcr tests]'.PHP_EOL, ob_get_clean());
89+
$this->assertContains('[not orm or phpcr tests]', ob_get_clean());
9290
}
9391

9492
protected function assertProcessExecuted(array $arguments, $successfull = true)
9593
{
96-
$process = $this->getMockBuilder('Symfony\Component\Process\Process')
97-
->disableOriginalConstructor()
98-
->getMock();
94+
$process = $this->createMock('Symfony\Component\Process\Process');
9995

100-
$process->expects($this->once())
101-
->method('run');
96+
$process->expects($this->once())->method('run');
10297

10398
$process->expects($this->any())
10499
->method('isSuccessful')
105-
->will($this->returnValue($successfull));
100+
->willReturn($successfull);
106101

107-
$processPlaceholder = $this->getMock('ProcessPlaceholder', array('getProcess'));
102+
$processPlaceholder = $this->getMockBuilder('ProcessPlaceholder')
103+
->setMethods(['getProcess'])
104+
->getMock();
108105
$processPlaceholder->expects($this->once())
109106
->method('getProcess')
110-
->will($this->returnValue($process));
107+
->willReturn($process);
111108

112109
$this->getProcessBuilder()
113110
->expects($this->at(self::$i++))
114111
->method('setArguments')
115112
->with($this->equalTo($arguments))
116-
->will($this->returnValue($processPlaceholder));
113+
->willReturn($processPlaceholder);
117114
}
118115

119116
protected function getProcessBuilder()
120117
{
121118
if (null === $this->processBuilder) {
122-
$this->processBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder');
119+
$this->processBuilder = $this->createMock('Symfony\Component\Process\ProcessBuilder');
123120
}
124121

125122
return $this->processBuilder;

0 commit comments

Comments
 (0)