-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
150f0a4
commit 0c81652
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Nijens\Utilities\Tests; | ||
|
||
/** | ||
* MockObject | ||
* | ||
* @author Niels Nijens <nijens.niels@gmail.com> | ||
* @package Nijens\Utilities\Tests | ||
**/ | ||
class MockObject | ||
{ | ||
public $argument; | ||
|
||
public function __construct($argument = null) | ||
{ | ||
$this->argument = $argument; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Nijens\Utilities\Tests; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Nijens\Utilities\ObjectFactory; | ||
|
||
/** | ||
* ObjectFactoryTest | ||
* | ||
* @author Niels Nijens <nijens.niels@gmail.com> | ||
* @package Nijens\Utilities\Tests | ||
**/ | ||
class ObjectFactoryTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* testGetInstance | ||
* | ||
* Tests if ObjectFactory::getInstance returns an ObjectFactory instance | ||
* | ||
* @access public | ||
* @return void | ||
**/ | ||
public function testGetInstance() | ||
{ | ||
$this->assertInstanceOf("Nijens\\Utilities\\ObjectFactory", ObjectFactory::getInstance() ); | ||
} | ||
|
||
/** | ||
* testNewInstance | ||
* | ||
* Tests if ObjectFactory::newInstance creates a new instance | ||
* | ||
* @access public | ||
* @return void | ||
**/ | ||
public function testNewInstance() | ||
{ | ||
$objectFactory = ObjectFactory::getInstance(); | ||
|
||
$this->assertInstanceOf("Nijens\\Utilities\\Tests\\MockObject", $objectFactory->newInstance("Nijens\\Utilities\\Tests\\MockObject") ); | ||
} | ||
|
||
/** | ||
* testNewInstanceWithArgumentArray | ||
* | ||
* Tests if ObjectFactory::newInstance creates a new instance with argument as constructor argument | ||
* | ||
* @depends testNewInstance | ||
* | ||
* @access public | ||
* @return void | ||
**/ | ||
public function testNewInstanceWithArgumentArray() | ||
{ | ||
$argumentValue = "test"; | ||
|
||
$objectFactory = ObjectFactory::getInstance(); | ||
$instance = $objectFactory->newInstance("Nijens\\Utilities\\Tests\\MockObject", array("argument" => $argumentValue) ); | ||
|
||
$this->assertSame($argumentValue, $instance->argument); | ||
} | ||
|
||
/** | ||
* testNewInstanceWithNonExistingClassNameReturnsNull | ||
* | ||
* Tests if ObjectFactory::newInstance for a non-existing class name returns null | ||
* | ||
* @depends testNewInstance | ||
* | ||
* @access public | ||
* @return void | ||
**/ | ||
public function testNewInstanceWithNonExistingClassNameReturnsNull() | ||
{ | ||
$objectFactory = ObjectFactory::getInstance(); | ||
|
||
$this->assertNull($objectFactory->newInstance("Nijens\\Utilities\\Tests\\NonExistingClass") ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters