From 7fe88e782c1e8f69c667afe1b5aedfe862056ce5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 5 Oct 2016 12:00:57 +0200 Subject: [PATCH] Add core unit tests (#170) --- tests/PHPSA/ApplicationTest.php | 39 ++++++++++ tests/PHPSA/IssuesCollectorTest.php | 33 +++++++++ tests/PHPSA/ScopePointerTest.php | 108 ++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 tests/PHPSA/ApplicationTest.php create mode 100644 tests/PHPSA/IssuesCollectorTest.php create mode 100644 tests/PHPSA/ScopePointerTest.php diff --git a/tests/PHPSA/ApplicationTest.php b/tests/PHPSA/ApplicationTest.php new file mode 100644 index 00000000..fa3e714e --- /dev/null +++ b/tests/PHPSA/ApplicationTest.php @@ -0,0 +1,39 @@ +assertInstanceOf('\PHPSA\Application', $application); + $this->assertInstanceOf('\Symfony\Component\Console\Application', $application); + } + + /** + * @covers \PHPSA\Application::getConfiguration + */ + public function testGetConfiguration() + { + $application = new Application(); + + $this->assertInstanceOf('\PHPSA\Configuration', $application->getConfiguration()); + } + + /** + * @covers \PHPSA\Application::getIssuesCollector + */ + public function testGetIssueCollector() + { + $application = new Application(); + + $this->assertInstanceOf('\PHPSA\IssuesCollector', $application->getIssuesCollector()); + } +} diff --git a/tests/PHPSA/IssuesCollectorTest.php b/tests/PHPSA/IssuesCollectorTest.php new file mode 100644 index 00000000..29d2a73a --- /dev/null +++ b/tests/PHPSA/IssuesCollectorTest.php @@ -0,0 +1,33 @@ +assertNull($collector->addIssue(100, 'Test issue', __FILE__, 26)); + $this->assertCount(1, $collector->getIssues()); + $this->assertSame( + [['type' => 100, 'message' => 'Test issue', 'file' => __FILE__, 'line' => 26]], + $collector->getIssues() + ); + } +} diff --git a/tests/PHPSA/ScopePointerTest.php b/tests/PHPSA/ScopePointerTest.php new file mode 100644 index 00000000..e66bd966 --- /dev/null +++ b/tests/PHPSA/ScopePointerTest.php @@ -0,0 +1,108 @@ +assertInstanceOf('\PHPSA\ScopePointer', $scopePointer); + } + + /** + * @covers \PHPSA\ScopePointer::getObject + */ + public function testGetObject() + { + $object = new \stdClass; + $scopePointer = new ScopePointer($object); + + $this->assertSame($object, $scopePointer->getObject()); + } + + /** + * @covers \PHPSA\ScopePointer::isClassMethod() + */ + public function testIsClassMethod() + { + $class = $this->getMockBuilder('\PHPSA\Definition\ClassMethod') + ->disableOriginalConstructor() + ->getMock(); + $scopePointer = new ScopePointer($class); + + $this->assertTrue($scopePointer->isClassMethod()); + } + + /** + * @covers \PHPSA\ScopePointer::isClassMethod() + * @dataProvider notClassMethodDataProvider + */ + public function testIsNotClassMethod($object) + { + $scopePointer = new ScopePointer($object); + + $this->assertFalse($scopePointer->isClassMethod()); + } + + /** + * @covers \PHPSA\ScopePointer::isFunction() + */ + public function testIsFunction() + { + $function = $this->getMockBuilder('\PHPSA\Definition\FunctionDefinition') + ->disableOriginalConstructor() + ->getMock(); + $scopePointer = new ScopePointer($function); + + $this->assertTrue($scopePointer->isFunction()); + } + + /** + * @covers \PHPSA\ScopePointer::isFunction() + * @dataProvider notFunctionDataProvider + */ + public function testIsNotFunction($object) + { + $scopePointer = new ScopePointer($object); + + $this->assertFalse($scopePointer->isFunction()); + } + + public function notClassMethodDataProvider() + { + $function = $this->getMockBuilder('\PHPSA\Definition\FunctionDefinition') + ->disableOriginalConstructor() + ->getMock(); + + return [ + 'String' => ['Random characters'], + 'Integer' => [42], + 'Float' => [pi()], + 'StdClass' => [new \StdClass], + 'FunctionDefinition' => [$function] + ]; + } + + public function notFunctionDataProvider() + { + $class = $this->getMockBuilder('\PHPSA\Definition\ClassMethod') + ->disableOriginalConstructor() + ->getMock(); + + return [ + 'String' => ['Random characters'], + 'Integer' => [42], + 'Float' => [pi()], + 'StdClass' => [new \StdClass], + 'ClassMethod' => [$class] + ]; + } +}