Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add GatewayLocator test and relevant exception

  • Loading branch information...
commit 3000c060bee78cdc50a17425a827f4486033d657 1 parent 20140ad
@pmjones pmjones authored
View
2  src.php
@@ -9,6 +9,7 @@
require_once __DIR__ . '/src/Aura/Sql/Column.php';
require_once __DIR__ . '/src/Aura/Sql/ColumnFactory.php';
require_once __DIR__ . '/src/Aura/Sql/Exception.php';
+require_once __DIR__ . '/src/Aura/Sql/Exception/NoSuchGateway.php';
require_once __DIR__ . '/src/Aura/Sql/Exception/NoSuchMaster.php';
require_once __DIR__ . '/src/Aura/Sql/Exception/NoSuchSlave.php';
require_once __DIR__ . '/src/Aura/Sql/ProfilerInterface.php';
@@ -24,4 +25,5 @@
require_once __DIR__ . '/src/Aura/Sql/AbstractMapper.php';
require_once __DIR__ . '/src/Aura/Sql/Gateway.php';
require_once __DIR__ . '/src/Aura/Sql/GatewayLocator.php';
+require_once __DIR__ . '/src/Aura/Sql/GatewayIterator.php';
require_once __DIR__ . '/src/Aura/Sql/UnitOfWork.php';
View
24 src/Aura/Sql/Exception/NoSuchGateway.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ *
+ * This file is part of the Aura Project for PHP.
+ *
+ * @package Aura.Sql
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ */
+namespace Aura\Sql\Exception;
+
+use Aura\Sql\Exception;
+
+/**
+ *
+ * No such slave exception
+ *
+ * @package Aura.Sql
+ *
+ */
+class NoSuchGateway extends Exception
+{
+}
View
1  src/Aura/Sql/Exception/NoSuchMaster.php
@@ -11,6 +11,7 @@
namespace Aura\Sql\Exception;
use Aura\Sql\Exception;
+
/**
*
* No such master exception
View
1  src/Aura/Sql/Exception/NoSuchSlave.php
@@ -11,6 +11,7 @@
namespace Aura\Sql\Exception;
use Aura\Sql\Exception;
+
/**
*
* No such slave exception
View
2  src/Aura/Sql/GatewayLocator.php
@@ -83,7 +83,7 @@ public function set($name, $spec)
public function get($name)
{
if (! isset($this->registry[$name])) {
- throw new Exception\GatewayNotMapped($name);
+ throw new Exception\NoSuchGateway($name);
}
if ($this->registry[$name] instanceof \Closure) {
View
78 tests/Aura/Sql/GatewayLocatorTest.php
@@ -0,0 +1,78 @@
+<?php
+namespace Aura\Sql;
+
+/**
+ * Test class for GatewayLocator.
+ * Generated by PHPUnit on 2012-09-27 at 23:05:48.
+ */
+class GatewayLocatorTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var GatewayLocator
+ */
+ protected $gateways;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $registry = [
+ 'Domain\Post\Entity' => function() {
+ $gateway = (object) ['type' => 'post'];
+ return $gateway;
+ },
+ 'Domain\Comment\Entity' => function() {
+ $gateway = (object) ['type' => 'comment'];
+ return $gateway;
+ },
+ 'Domain\Author\Entity' => function() {
+ $gateway = (object) ['type' => 'author'];
+ return $gateway;
+ },
+ ];
+
+ $this->gateways = new GatewayLocator($registry);
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
+ parent::tearDown();
+ }
+
+ /**
+ * @covers Aura\Sql\GatewayLocator::set
+ * @todo Implement testSet().
+ */
+ public function testSetAndGet()
+ {
+ $this->gateways->set('Domain\Category\Entity', function () {
+ $gateway = (object) ['type' => 'category'];
+ return $gateway;
+ });
+
+ $gateway = $this->gateways->get('Domain\Category\Entity');
+ $this->assertTrue($gateway->type == 'category');
+ }
+
+ public function testGet_noSuchGateway()
+ {
+ $this->setExpectedException('Aura\Sql\Exception\NoSuchGateway');
+ $gateway = $this->gateways->get('no-such-gateway');
+ }
+
+ public function test_iterator()
+ {
+ $expect = ['post', 'comment', 'author'];
+ foreach ($this->gateways as $gateway) {
+ $actual[] = $gateway->type;
+ }
+ $this->assertSame($expect, $actual);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.