Skip to content

Commit

Permalink
Added unit tests for ObjectFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
niels-nijens committed Jan 10, 2015
1 parent 150f0a4 commit 0c81652
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/MockObject.php
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;
}
}
80 changes: 80 additions & 0 deletions tests/ObjectFactoryTest.php
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") );
}
}
1 change: 1 addition & 0 deletions tests/UnregisterableCallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testWithValidCallbackNotCalledAfterUnregister()
* Tests if UnregisterableCallback throws an InvalidArgumentException when the first argument is not callable
*
* @expectedException InvalidArgumentException
*
* @access public
* @return void
**/
Expand Down

0 comments on commit 0c81652

Please sign in to comment.