Skip to content

Commit cd629be

Browse files
author
ksimka
committed
Added testcase for mocking singleton with newInstanceWithoutConstructor when possible
1 parent ba8784d commit cd629be

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/GeneratorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
class Framework_MockObject_GeneratorTest extends PHPUnit_Framework_TestCase
33
{
4+
/**
5+
* @var PHPUnit_Framework_MockObject_Generator
6+
*/
47
protected $generator;
58

69
protected function setUp()
@@ -162,5 +165,17 @@ public static function getMockForTraitExpectsInvalidArgumentExceptionDataprovide
162165
'trait does not exist' => array('AbstractTraitDoesNotExist', 'TraitTest')
163166
);
164167
}
168+
169+
/**
170+
*
171+
*/
172+
public function testGetMockForSingletonWithReflectionSuccess()
173+
{
174+
// Probably, this should be moved to tests/autoload.php
175+
require_once __DIR__ . '/_fixture/SingletonClass.php';
176+
177+
$mock = $this->generator->getMock('SingletonClass', array('doSomething'), array(), '', false);
178+
$this->assertInstanceOf('SingletonClass', $mock);
179+
}
165180
}
166181

tests/_fixture/SingletonClass.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
class SingletonClass
4+
{
5+
public static function getInstance()
6+
{
7+
}
8+
9+
public function doSomething()
10+
{
11+
}
12+
13+
protected function __construct()
14+
{
15+
}
16+
17+
final private function __sleep()
18+
{
19+
}
20+
21+
final private function __wakeup()
22+
{
23+
}
24+
25+
final private function __clone()
26+
{
27+
}
28+
}

0 commit comments

Comments
 (0)