Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 2, 2015
1 parent 1f13786 commit 4f526b7
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions tests/GeneratorTest.php
Expand Up @@ -17,15 +17,16 @@ protected function setUp()
*/
public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock()
{
$this->generator->getMock('StdClass', [0]);
$this->generator->getMock(StdClass::class, [0]);
}

/**
* @covers PHPUnit_Framework_MockObject_Generator::getMock
*/
public function testGetMockCanCreateNonExistingFunctions()
{
$mock = $this->generator->getMock('StdClass', ['testFunction']);
$mock = $this->generator->getMock(StdClass::class, ['testFunction']);

$this->assertTrue(method_exists($mock, 'testFunction'));
}

Expand All @@ -36,33 +37,29 @@ public function testGetMockCanCreateNonExistingFunctions()
*/
public function testGetMockGeneratorFails()
{
$mock = $this->generator->getMock('StdClass', ['foo', 'foo']);
$this->generator->getMock(StdClass::class, ['foo', 'foo']);
}

/**
* @covers PHPUnit_Framework_MockObject_Generator::getMock
* @covers PHPUnit_Framework_MockObject_Generator::isMethodNameBlacklisted
* @covers PHPUnit_Framework_MockObject_Generator::getMock
* @covers PHPUnit_Framework_MockObject_Generator::isMethodNameBlacklisted
* @requires PHP 7
*/
public function testGetMockBlacklistedMethodNamesPhp7()
{
if (PHP_MAJOR_VERSION < 7) {
$this->markTestSkipped('PHP >= 7.0.0 required');

return;
}

$mock = $this->generator->getMock('InterfaceWithSemiReservedMethodName');
$mock = $this->generator->getMock(InterfaceWithSemiReservedMethodName::class);

$this->assertTrue(method_exists($mock, 'unset'));
$this->assertInstanceOf('InterfaceWithSemiReservedMethodName', $mock);
$this->assertInstanceOf(InterfaceWithSemiReservedMethodName::class, $mock);
}

/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
*/
public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces()
{
$mock = $this->generator->getMockForAbstractClass('Countable');
$mock = $this->generator->getMockForAbstractClass(Countable::class);

$this->assertTrue(method_exists($mock, 'count'));
}

Expand All @@ -71,7 +68,8 @@ public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces()
*/
public function testGetMockForAbstractClassStubbingAbstractClass()
{
$mock = $this->generator->getMockForAbstractClass('AbstractMockTestClass');
$mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class);

$this->assertTrue(method_exists($mock, 'doSomething'));
}

Expand All @@ -81,7 +79,7 @@ public function testGetMockForAbstractClassStubbingAbstractClass()
public function testGetMockForAbstractClassWithNonExistentMethods()
{
$mock = $this->generator->getMockForAbstractClass(
'AbstractMockTestClass',
AbstractMockTestClass::class,
[],
'',
true,
Expand All @@ -99,7 +97,7 @@ public function testGetMockForAbstractClassWithNonExistentMethods()
*/
public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMethodWhenNoMethodsWereInformed()
{
$mock = $this->generator->getMockForAbstractClass('AbstractMockTestClass');
$mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class);

$mock->expects($this->any())
->method('doSomething')
Expand All @@ -116,7 +114,7 @@ public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMetho
*/
public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName)
{
$mock = $this->generator->getMockForAbstractClass($className, [], $mockClassName);
$this->generator->getMockForAbstractClass($className, [], $mockClassName);
}

/**
Expand All @@ -125,17 +123,14 @@ public function testGetMockForAbstractClassExpectingInvalidArgumentException($cl
*/
public function testGetMockForAbstractClassAbstractClassDoesNotExist()
{
$mock = $this->generator->getMockForAbstractClass('Tux');
$this->generator->getMockForAbstractClass('Tux');
}

/**
* Dataprovider for test "testGetMockForAbstractClassExpectingInvalidArgumentException"
*/
public static function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider()
public function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider()
{
return [
'className not a string' => [[], ''],
'mockClassName not a string' => ['Countable', new StdClass],
'mockClassName not a string' => [Countable::class, new StdClass],
];
}

Expand All @@ -145,7 +140,7 @@ public static function getMockForAbstractClassExpectsInvalidArgumentExceptionDat
public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods()
{
$mock = $this->generator->getMockForTrait(
'AbstractTrait',
AbstractTrait::class,
[],
'',
true,
Expand All @@ -165,16 +160,15 @@ public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods()
*/
public function testGetMockForTraitStubbingAbstractMethod()
{
$mock = $this->generator->getMockForTrait('AbstractTrait');
$mock = $this->generator->getMockForTrait(AbstractTrait::class);

$this->assertTrue(method_exists($mock, 'doSomething'));
}

public function testGetMockForSingletonWithReflectionSuccess()
{
// Probably, this should be moved to tests/autoload.php
require_once __DIR__ . '/_fixture/SingletonClass.php';
$mock = $this->generator->getMock(SingletonClass::class, ['doSomething'], [], '', false);

$mock = $this->generator->getMock('SingletonClass', ['doSomething'], [], '', false);
$this->assertInstanceOf('SingletonClass', $mock);
}
}

0 comments on commit 4f526b7

Please sign in to comment.