Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #183 from DannyvdSluijs/master
Browse files Browse the repository at this point in the history
Add core unit tests (#170)
  • Loading branch information
Enrico Höschler committed Nov 21, 2016
2 parents d8102bc + 0f71439 commit 35ec269
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/PHPSA/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tests\PHPSA;

use PHPSA\Application;

class ApplicationTest extends TestCase
{
/**
* @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());
}
}
24 changes: 24 additions & 0 deletions tests/PHPSA/IssuesCollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\PHPSA;

use PHPSA\IssueLocation;
use PHPSA\IssuesCollector;
use PHPSA\Issue;

class IssuesCollectorTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers \PHPSA\IssuesCollector::addIssue()
* @covers \PHPSA\IssuesCollector::getIssues()
*/
public function testAddingIssue()
{
$collector = new IssuesCollector();
$issue = new Issue(__FUNCTION__, 'Test issue', new IssueLocation(__FILE__, 26));

$this->assertNull($collector->addIssue($issue));
$this->assertCount(1, $collector->getIssues());
$this->assertSame([$issue], $collector->getIssues());
}
}
97 changes: 97 additions & 0 deletions tests/PHPSA/ScopePointerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Tests\PHPSA;

use PHPSA\ScopePointer;

class ScopePointerTest extends TestCase
{
/**
* @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]
];
}
}

0 comments on commit 35ec269

Please sign in to comment.