Skip to content

Commit

Permalink
Merge pull request #111 from doctrine/cleanup/move-to-correct-phpunit…
Browse files Browse the repository at this point in the history
…-assertions

Cleanup: move to correct phpunit assertions
  • Loading branch information
lcobucci authored Dec 30, 2016
2 parents 0d9fb6d + 38bff01 commit c26cb71
Show file tree
Hide file tree
Showing 24 changed files with 496 additions and 476 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/Common/Annotations/DocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ final class DocParser
/**
* An array of default namespaces if operating in simple mode.
*
* @var array
* @var string[]
*/
private $namespaces = array();

Expand Down Expand Up @@ -286,7 +286,7 @@ public function setIgnoreNotImportedAnnotations($bool)
/**
* Sets the default namespaces.
*
* @param array $namespace
* @param string $namespace
*
* @return void
*
Expand Down
220 changes: 111 additions & 109 deletions tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class TargetTest extends \PHPUnit_Framework_TestCase
*/
public function testValidMixedTargets()
{
$target = new Target(array("value" => array("ALL")));
$this->assertEquals(Target::TARGET_ALL, $target->targets);
$target = new Target(array('value' => array('ALL')));
self::assertEquals(Target::TARGET_ALL, $target->targets);

$target = new Target(array("value" => array("METHOD", "METHOD")));
$this->assertEquals(Target::TARGET_METHOD, $target->targets);
$this->assertNotEquals(Target::TARGET_PROPERTY, $target->targets);
$target = new Target(array('value' => array('METHOD', 'METHOD')));
self::assertEquals(Target::TARGET_METHOD, $target->targets);
self::assertNotEquals(Target::TARGET_PROPERTY, $target->targets);

$target = new Target(array("value" => array("PROPERTY", "METHOD")));
$this->assertEquals(Target::TARGET_METHOD | Target::TARGET_PROPERTY, $target->targets);
$target = new Target(array('value' => array('PROPERTY', 'METHOD')));
self::assertEquals(Target::TARGET_METHOD | Target::TARGET_PROPERTY, $target->targets);
}
}

20 changes: 10 additions & 10 deletions tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ protected function getReader(DocParser $parser = null)
public function testMethodAnnotationFromTrait()
{
$reader = $this->getReader();
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassUsesTrait');
$ref = new \ReflectionClass(Fixtures\ClassUsesTrait::class);

$annotations = $reader->getMethodAnnotations($ref->getMethod('someMethod'));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Bar\Autoload', $annotations[0]);
self::assertInstanceOf(Bar\Autoload::class, $annotations[0]);

$annotations = $reader->getMethodAnnotations($ref->getMethod('traitMethod'));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Autoload', $annotations[0]);
self::assertInstanceOf(Fixtures\Annotation\Autoload::class, $annotations[0]);
}

public function testMethodAnnotationFromOverwrittenTrait()
{
$reader = $this->getReader();
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassOverwritesTrait');
$ref = new \ReflectionClass(Fixtures\ClassOverwritesTrait::class);

$annotations = $reader->getMethodAnnotations($ref->getMethod('traitMethod'));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Bar2\Autoload', $annotations[0]);
self::assertInstanceOf(Bar2\Autoload::class, $annotations[0]);
}

public function testPropertyAnnotationFromTrait()
{
$reader = $this->getReader();
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassUsesTrait');
$ref = new \ReflectionClass(Fixtures\ClassUsesTrait::class);

$annotations = $reader->getPropertyAnnotations($ref->getProperty('aProperty'));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Bar\Autoload', $annotations[0]);
self::assertInstanceOf(Bar\Autoload::class, $annotations[0]);

$annotations = $reader->getPropertyAnnotations($ref->getProperty('traitProperty'));
$this->assertInstanceOf('Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Autoload', $annotations[0]);
self::assertInstanceOf(Fixtures\Annotation\Autoload::class, $annotations[0]);
}

public function testOmitNotRegisteredAnnotation()
Expand All @@ -58,10 +58,10 @@ public function testOmitNotRegisteredAnnotation()
$parser->setIgnoreNotImportedAnnotations(true);

$reader = $this->getReader($parser);
$ref = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassWithNotRegisteredAnnotationUsed');
$ref = new \ReflectionClass(Fixtures\ClassWithNotRegisteredAnnotationUsed::class);

$annotations = $reader->getMethodAnnotations($ref->getMethod('methodWithNotRegisteredAnnotation'));
$this->assertEquals(array(), $annotations);
self::assertEquals(array(), $annotations);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AnnotationRegistryTest extends \PHPUnit_Framework_TestCase
{
protected $class = 'Doctrine\Common\Annotations\AnnotationRegistry';
protected $class = AnnotationRegistry::class;

/**
* @runInSeparateProcess
Expand All @@ -18,13 +18,13 @@ public function testReset()
$this->setStaticField($this->class, 'autoloadNamespaces', $data);
$this->setStaticField($this->class, 'loaders', $data);

$this->assertEquals($data, $this->getStaticField($this->class, 'autoloadNamespaces'));
$this->assertEquals($data, $this->getStaticField($this->class, 'loaders'));
self::assertEquals($data, $this->getStaticField($this->class, 'autoloadNamespaces'));
self::assertEquals($data, $this->getStaticField($this->class, 'loaders'));

AnnotationRegistry::reset();

$this->assertEmpty($this->getStaticField($this->class, 'autoloadNamespaces'));
$this->assertEmpty($this->getStaticField($this->class, 'loaders'));
self::assertEmpty($this->getStaticField($this->class, 'autoloadNamespaces'));
self::assertEmpty($this->getStaticField($this->class, 'loaders'));
}

/**
Expand All @@ -35,7 +35,7 @@ public function testRegisterAutoloadNamespaces()
$this->setStaticField($this->class, 'autoloadNamespaces', array('foo' => 'bar'));

AnnotationRegistry::registerAutoloadNamespaces(array('test' => 'bar'));
$this->assertEquals(array('foo' => 'bar', 'test' => 'bar'), $this->getStaticField($this->class, 'autoloadNamespaces'));
self::assertEquals(array('foo' => 'bar', 'test' => 'bar'), $this->getStaticField($this->class, 'autoloadNamespaces'));
}

/**
Expand Down
16 changes: 9 additions & 7 deletions tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;

class CachedReaderTest extends AbstractReaderTest
{
Expand All @@ -16,7 +17,7 @@ public function testIgnoresStaleCache()
$cache = time() - 10;
touch(__DIR__.'/Fixtures/Controller.php', $cache + 10);

$this->doTestCacheStale('Doctrine\Tests\Common\Annotations\Fixtures\Controller', $cache);
$this->doTestCacheStale(Fixtures\Controller::class, $cache);
}

/**
Expand All @@ -28,7 +29,7 @@ public function testIgnoresStaleCacheWithParentClass()
touch(__DIR__.'/Fixtures/ControllerWithParentClass.php', $cache - 10);
touch(__DIR__.'/Fixtures/AbstractController.php', $cache + 10);

$this->doTestCacheStale('Doctrine\Tests\Common\Annotations\Fixtures\ControllerWithParentClass', $cache);
$this->doTestCacheStale(Fixtures\ControllerWithParentClass::class, $cache);
}

/**
Expand All @@ -40,7 +41,7 @@ public function testIgnoresStaleCacheWithTraits()
touch(__DIR__.'/Fixtures/ControllerWithTrait.php', $cache - 10);
touch(__DIR__.'/Fixtures/Traits/SecretRouteTrait.php', $cache + 10);

$this->doTestCacheStale('Doctrine\Tests\Common\Annotations\Fixtures\ControllerWithTrait', $cache);
$this->doTestCacheStale(Fixtures\ControllerWithTrait::class, $cache);
}

/**
Expand All @@ -54,7 +55,7 @@ public function testIgnoresStaleCacheWithTraitsThatUseOtherTraits()
touch(__DIR__ . '/Fixtures/Traits/EmptyTrait.php', $cache + 10);

$this->doTestCacheStale(
'Doctrine\Tests\Common\Annotations\Fixtures\ClassThatUsesTraitThatUsesAnotherTrait',
Fixtures\ClassThatUsesTraitThatUsesAnotherTrait::class,
$cache
);
}
Expand All @@ -70,7 +71,7 @@ public function testIgnoresStaleCacheWithInterfacesThatExtendOtherInterfaces()
touch(__DIR__ . '/Fixtures/EmptyInterface.php', $cache + 10);

$this->doTestCacheStale(
'Doctrine\Tests\Common\Annotations\Fixtures\InterfaceThatExtendsAnInterface',
Fixtures\InterfaceThatExtendsAnInterface::class,
$cache
);
}
Expand All @@ -79,7 +80,8 @@ protected function doTestCacheStale($className, $lastCacheModification)
{
$cacheKey = $className;

$cache = $this->createMock('Doctrine\Common\Cache\Cache');
/* @var $cache Cache|\PHPUnit_Framework_MockObject_MockObject */
$cache = $this->createMock(Cache::class);
$cache
->expects($this->at(0))
->method('fetch')
Expand Down Expand Up @@ -107,7 +109,7 @@ protected function doTestCacheStale($className, $lastCacheModification)
$route = new Route();
$route->pattern = '/someprefix';

$this->assertEquals(array($route), $reader->getClassAnnotations(new \ReflectionClass($className)));
self::assertEquals(array($route), $reader->getClassAnnotations(new \ReflectionClass($className)));
}

protected function getReader()
Expand Down
52 changes: 26 additions & 26 deletions tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ public function testMarkerAnnotation()
{
$lexer = new DocLexer;

$lexer->setInput("@Name");
$this->assertNull($lexer->token);
$this->assertNull($lexer->lookahead);
$lexer->setInput('@Name');
self::assertNull($lexer->token);
self::assertNull($lexer->lookahead);

$this->assertTrue($lexer->moveNext());
$this->assertNull($lexer->token);
$this->assertEquals('@', $lexer->lookahead['value']);
self::assertTrue($lexer->moveNext());
self::assertNull($lexer->token);
self::assertEquals('@', $lexer->lookahead['value']);

$this->assertTrue($lexer->moveNext());
$this->assertEquals('@', $lexer->token['value']);
$this->assertEquals('Name', $lexer->lookahead['value']);
self::assertTrue($lexer->moveNext());
self::assertEquals('@', $lexer->token['value']);
self::assertEquals('Name', $lexer->lookahead['value']);

$this->assertFalse($lexer->moveNext());
self::assertFalse($lexer->moveNext());
}

public function testScannerTokenizesDocBlockWhitConstants()
{
$lexer = new DocLexer();
$docblock = '@AnnotationWithConstants(PHP_EOL, ClassWithConstants::SOME_VALUE, ClassWithConstants::CONSTANT_, ClassWithConstants::CONST_ANT3, \Doctrine\Tests\Common\Annotations\Fixtures\IntefaceWithConstants::SOME_VALUE)';
$docblock = '@AnnotationWithConstants(PHP_EOL, ClassWithConstants::SOME_VALUE, ClassWithConstants::CONSTANT_, ClassWithConstants::CONST_ANT3, \Doctrine\Tests\Common\Annotations\Fixtures\InterfaceWithConstants::SOME_VALUE)';

$tokens = array (
array(
Expand Down Expand Up @@ -87,13 +87,13 @@ public function testScannerTokenizesDocBlockWhitConstants()
'type' => DocLexer::T_COMMA,
),
array(
'value' => '\\Doctrine\\Tests\\Common\\Annotations\\Fixtures\\IntefaceWithConstants::SOME_VALUE',
'value' => '\\Doctrine\\Tests\\Common\\Annotations\\Fixtures\\InterfaceWithConstants::SOME_VALUE',
'position' => 129,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => ')',
'position' => 206,
'position' => 207,
'type' => DocLexer::T_CLOSE_PARENTHESIS,
)

Expand All @@ -104,12 +104,12 @@ public function testScannerTokenizesDocBlockWhitConstants()
foreach ($tokens as $expected) {
$lexer->moveNext();
$lookahead = $lexer->lookahead;
$this->assertEquals($expected['value'], $lookahead['value']);
$this->assertEquals($expected['type'], $lookahead['type']);
$this->assertEquals($expected['position'], $lookahead['position']);
self::assertEquals($expected['value'], $lookahead['value']);
self::assertEquals($expected['type'], $lookahead['type']);
self::assertEquals($expected['position'], $lookahead['position']);
}

$this->assertFalse($lexer->moveNext());
self::assertFalse($lexer->moveNext());
}


Expand Down Expand Up @@ -146,12 +146,12 @@ public function testScannerTokenizesDocBlockWhitInvalidIdentifier()
foreach ($tokens as $expected) {
$lexer->moveNext();
$lookahead = $lexer->lookahead;
$this->assertEquals($expected['value'], $lookahead['value']);
$this->assertEquals($expected['type'], $lookahead['type']);
$this->assertEquals($expected['position'], $lookahead['position']);
self::assertEquals($expected['value'], $lookahead['value']);
self::assertEquals($expected['type'], $lookahead['type']);
self::assertEquals($expected['position'], $lookahead['position']);
}

$this->assertFalse($lexer->moveNext());
self::assertFalse($lexer->moveNext());
}

/**
Expand All @@ -163,7 +163,7 @@ public function testWithinDoubleQuotesVeryVeryLongStringWillNotOverflowPregSplit

$lexer->setInput('"' . str_repeat('.', 20240) . '"');

$this->assertInternalType('array', $lexer->glimpse());
self::assertInternalType('array', $lexer->glimpse());
}

/**
Expand Down Expand Up @@ -207,11 +207,11 @@ public function testRecognizesDoubleQuotesEscapeSequence()
foreach ($tokens as $expected) {
$lexer->moveNext();
$lookahead = $lexer->lookahead;
$this->assertEquals($expected['value'], $lookahead['value']);
$this->assertEquals($expected['type'], $lookahead['type']);
$this->assertEquals($expected['position'], $lookahead['position']);
self::assertEquals($expected['value'], $lookahead['value']);
self::assertEquals($expected['type'], $lookahead['type']);
self::assertEquals($expected['position'], $lookahead['position']);
}

$this->assertFalse($lexer->moveNext());
self::assertFalse($lexer->moveNext());
}
}
Loading

0 comments on commit c26cb71

Please sign in to comment.