-
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
0 parents
commit 11936cd
Showing
10 changed files
with
247 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,4 @@ | ||
vendor/ | ||
composer.lock | ||
phpunit.xml | ||
.DS_Store |
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,11 @@ | ||
language: php | ||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
before_script: | ||
- composer install --dev | ||
script: | ||
- ./vendor/bin/phpunit --coverage-text | ||
- ./vendor/bin/phpcs --extensions=php --report=summary --standard=PSR2 ./src ./tests |
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,25 @@ | ||
{ | ||
"name": "minphp/container", | ||
"description": "A Dependency Injection Container based on Pimple", | ||
"homepage": "http://github.com/phillipsdata/minphp-container", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Cody Phillips", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0", | ||
"container-interop/container-interop": "~1.0", | ||
"pimple/pimple": "~3.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.0", | ||
"squizlabs/php_codesniffer": "~2.2" | ||
}, | ||
"autoload": { | ||
"psr-4": {"minphp\\Container\\": "src"} | ||
} | ||
} |
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
bootstrap="./vendor/autoload.php" | ||
backupGlobals="false"> | ||
<testsuites> | ||
<testsuite name="minphp/Container"> | ||
<directory suffix="Test.php">tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,48 @@ | ||
<?php | ||
namespace minphp\Container; | ||
|
||
use Pimple\Container as PimpleContainer; | ||
use minphp\Container\Exception\NotFoundException; | ||
|
||
/** | ||
* A Container that extends Pimple using a standards compliant interface | ||
* | ||
*/ | ||
class Container extends PimpleContainer implements ContainerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($id) | ||
{ | ||
if (!$this->offsetExists($id)) { | ||
throw new NotFoundException(sprintf('Identifier "%s" is not defined.', $id)); | ||
} | ||
|
||
return $this->offsetGet($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($id) | ||
{ | ||
return $this->offsetExists($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function set($id, $value) | ||
{ | ||
$this->offsetSet($id, $value); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function remove($id) | ||
{ | ||
$this->offsetUnset($id); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
namespace minphp\Container; | ||
|
||
/** | ||
* An interface allowing injection of a container | ||
* | ||
*/ | ||
interface ContainerAwareInterface | ||
{ | ||
/** | ||
* Adds the container | ||
* | ||
* @param minphp\Container\ContainerInterface $container | ||
*/ | ||
public function setContainer(ContainerInterface $container = null); | ||
|
||
/** | ||
* Fetches a container | ||
* | ||
* @return minphp\Container\ContainerInterface | ||
*/ | ||
public function getContainer(); | ||
} |
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,26 @@ | ||
<?php | ||
namespace minphp\Container; | ||
|
||
use Interop\Container\ContainerInterface as InteropContainerInterface; | ||
|
||
/** | ||
* Container interface that expands on the Interop\Container\ContainerInterface | ||
* | ||
*/ | ||
interface ContainerInterface extends InteropContainerInterface | ||
{ | ||
/** | ||
* Adds an entry to the container | ||
* | ||
* @param string $id Identifier of the entry to add | ||
* @param mixed $value The entry to add to the container | ||
*/ | ||
public function set($id, $value); | ||
|
||
/** | ||
* Removes an entry from the container | ||
* | ||
* @param string $id Identifier of the entry to remove | ||
*/ | ||
public function remove($id); | ||
} |
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,9 @@ | ||
<?php | ||
namespace minphp\Container\Exception; | ||
|
||
use InvalidArgumentException; | ||
use Interop\Container\Exception\NotFoundException as NotFoundExceptionInterface; | ||
|
||
class NotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface | ||
{ | ||
} |
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,72 @@ | ||
<?php | ||
namespace minphp\Container; | ||
|
||
/** | ||
* @coversDefaultClass \minphp\Container\Container | ||
*/ | ||
class ContainerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $Container; | ||
|
||
public function setUp() | ||
{ | ||
$this->Container = new Container(); | ||
} | ||
|
||
/** | ||
* @covers ::get | ||
*/ | ||
public function testGet() | ||
{ | ||
$this->Container->set('id', 'value'); | ||
$this->assertEquals('value', $this->Container->get('id')); | ||
} | ||
|
||
/** | ||
* @covers ::get | ||
* @expectedException \minphp\Container\Exception\NotFoundException | ||
*/ | ||
public function testGetException() | ||
{ | ||
$this->assertEquals('value', $this->Container->get('non-existent-id')); | ||
} | ||
|
||
/** | ||
* @covers ::has | ||
*/ | ||
public function testHas() | ||
{ | ||
$this->Container->set('id', 'value'); | ||
$this->assertTrue($this->Container->has('id')); | ||
$this->assertFalse($this->Container->has('non-existent-id')); | ||
} | ||
|
||
/** | ||
* @covers ::set | ||
*/ | ||
public function testSet() | ||
{ | ||
$this->Container->set( | ||
'queue', | ||
function($c) { | ||
return new \SplQueue(); | ||
} | ||
); | ||
$queue = $this->Container->get('queue'); | ||
$queue->enqueue('hello'); | ||
|
||
$this->assertEquals('hello', $this->Container->get('queue')->dequeue()); | ||
} | ||
|
||
/** | ||
* @covers ::remove | ||
*/ | ||
public function testRemove() | ||
{ | ||
$this->Container->set('id', 'value'); | ||
$this->assertTrue($this->Container->has('id')); | ||
|
||
$this->Container->remove('id'); | ||
$this->assertFalse($this->Container->has('id')); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
namespace minphp\Container\Exception; | ||
|
||
/** | ||
* @coversDefaultClass \minphp\Container\Exception\NotFoundException | ||
*/ | ||
class NotFoundExceptionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testInstance() | ||
{ | ||
$this->assertInstanceOf('\Interop\Container\Exception\NotFoundException', new NotFoundException()); | ||
} | ||
} |