Properly namespace tests

This commit is contained in:
Timothy Warren 2016-08-29 11:34:25 -04:00
parent 2adb02daaa
commit 8f2ec8d4ed
16 changed files with 80 additions and 53 deletions

View File

@ -1,8 +1,10 @@
<?php <?php
namespace Aviat\Ion\Tests;
use Aviat\Ion\Model as BaseModel; use Aviat\Ion\Model as BaseModel;
class BaseModelTest extends Ion_TestCase { class BaseModelTest extends \Ion_TestCase {
public function testBaseModelSanity() public function testBaseModelSanity()
{ {

View File

@ -1,20 +1,22 @@
<?php <?php
namespace Aviat\Ion\Tests\Cache\Driver;
trait CacheDriverBase { trait CacheDriverBase {
protected $foo = [ protected $foo = [
'bar' => [ 'bar' => [
'baz' => 'foobar' 'baz' => 'foobar'
] ]
]; ];
protected $bar = 'secondvalue'; protected $bar = 'secondvalue';
public function testHasCacheDriver() public function testHasCacheDriver()
{ {
$this->assertTrue((bool) $this->driver); $this->assertTrue((bool) $this->driver);
} }
public function testDriverGetSet() public function testDriverGetSet()
{ {
$this->driver->set('foo', $this->foo); $this->driver->set('foo', $this->foo);
@ -22,21 +24,21 @@ trait CacheDriverBase {
$this->assertEquals($this->driver->get('foo'), $this->foo); $this->assertEquals($this->driver->get('foo'), $this->foo);
$this->assertEquals($this->driver->get('bar'), 'baz'); $this->assertEquals($this->driver->get('bar'), 'baz');
} }
public function testInvalidate() public function testInvalidate()
{ {
$this->driver->set('foo', $this->foo); $this->driver->set('foo', $this->foo);
$this->driver->invalidate('foo'); $this->driver->invalidate('foo');
$this->assertEmpty($this->driver->get('foo')); $this->assertEmpty($this->driver->get('foo'));
} }
public function testInvalidateAll() public function testInvalidateAll()
{ {
$this->driver->set('foo', $this->foo); $this->driver->set('foo', $this->foo);
$this->driver->set('bar', $this->bar); $this->driver->set('bar', $this->bar);
$this->driver->invalidateAll(); $this->driver->invalidateAll();
$this->assertEmpty($this->driver->get('foo')); $this->assertEmpty($this->driver->get('foo'));
$this->assertEmpty($this->driver->get('bar')); $this->assertEmpty($this->driver->get('bar'));
} }

View File

@ -1,10 +1,10 @@
<?php <?php
require_once('CacheDriverBase.php'); namespace Aviat\Ion\Tests\Cache\Driver;
use Aviat\Ion\Cache\Driver\NullDriver; use Aviat\Ion\Cache\Driver\NullDriver;
class CacheNullDriverTest extends Ion_TestCase { class CacheNullDriverTest extends \Ion_TestCase {
use CacheDriverBase; use CacheDriverBase;
protected $driver; protected $driver;

View File

@ -1,11 +1,11 @@
<?php <?php
require_once('CacheDriverBase.php'); namespace Aviat\Ion\Tests\Cache\Driver;
use Aviat\Ion\Config; use Aviat\Ion\Config;
use Aviat\Ion\Cache\Driver\RedisDriver; use Aviat\Ion\Cache\Driver\RedisDriver;
class CacheRedisDriverTestTwo extends Ion_TestCase { class CacheRedisDriverTestTwo extends \Ion_TestCase {
use CacheDriverBase; use CacheDriverBase;
protected $driver; protected $driver;

View File

@ -1,14 +1,14 @@
<?php <?php
require_once('CacheDriverBase.php'); namespace Aviat\Ion\Tests\Cache\Driver;
use Aviat\Ion\Cache\Driver\RedisDriver; use Aviat\Ion\Cache\Driver\RedisDriver;
class CacheRedisDriverTest extends Ion_TestCase { class CacheRedisDriverTest extends \Ion_TestCase {
use CacheDriverBase; use CacheDriverBase;
protected $driver; protected $driver;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();

View File

@ -1,15 +1,15 @@
<?php <?php
require_once('CacheDriverBase.php'); namespace Aviat\Ion\Tests\Cache\Driver;
use Aviat\Ion\Friend; use Aviat\Ion\Friend;
use Aviat\Ion\Cache\Driver\SQLDriver; use Aviat\Ion\Cache\Driver\SQLDriver;
class CacheSQLDriverTest extends Ion_TestCase { class CacheSQLDriverTest extends \Ion_TestCase {
use CacheDriverBase; use CacheDriverBase;
protected $driver; protected $driver;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();

View File

@ -1,8 +1,10 @@
<?php <?php
namespace Aviat\Ion\Tests;
use Aviat\Ion\Config; use Aviat\Ion\Config;
class ConfigTest extends Ion_TestCase { class ConfigTest extends \Ion_TestCase {
public function setUp() public function setUp()
{ {
@ -30,14 +32,14 @@ class ConfigTest extends Ion_TestCase {
$this->config->set(['apple', 'sauce', 'is'], 'great'); $this->config->set(['apple', 'sauce', 'is'], 'great');
$apple = $this->config->get('apple'); $apple = $this->config->get('apple');
$this->assertEquals('great', $apple['sauce']['is'], "Config value not set correctly"); $this->assertEquals('great', $apple['sauce']['is'], "Config value not set correctly");
$this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed."); $this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed.");
} }
public function testConfigBadSet() public function testConfigBadSet()
{ {
$this->setExpectedException('InvalidArgumentException'); $this->expectException('InvalidArgumentException');
$this->config->set(NULL, FALSE); $this->config->set(NULL, FALSE);
} }

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Aviat\Ion\Tests\Di;
use Aviat\Ion\Di\Container; use Aviat\Ion\Di\Container;
use Aviat\Ion\Di\ContainerAware; use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
@ -7,7 +9,7 @@ use Aviat\Ion\Di\Exception\ContainerException;
class Aware { class Aware {
use ContainerAware; use ContainerAware;
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
$this->container = $container; $this->container = $container;
@ -15,20 +17,20 @@ class Aware {
} }
class ContainerAwareTest extends Ion_TestCase { class ContainerAwareTest extends \Ion_TestCase {
public function setUp() public function setUp()
{ {
$this->container = new Container(); $this->container = new Container();
$this->aware = new Aware($this->container); $this->aware = new Aware($this->container);
} }
public function testContainerAwareTrait() public function testContainerAwareTrait()
{ {
// The container was set in setup // The container was set in setup
// check that the get method returns the same // check that the get method returns the same
$this->assertSame($this->container, $this->aware->getContainer()); $this->assertSame($this->container, $this->aware->getContainer());
$container2 = new Container([ $container2 = new Container([
'foo' => 'bar', 'foo' => 'bar',
'baz' => 'foobar' 'baz' => 'foobar'

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Aviat\Ion\Tests\Di;
use Aviat\Ion\Di\Container; use Aviat\Ion\Di\Container;
use Aviat\Ion\Di\Exception\ContainerException; use Aviat\Ion\Di\Exception\ContainerException;
use Monolog\Logger; use Monolog\Logger;
@ -7,7 +9,7 @@ use Monolog\Handler\TestHandler;
use Monolog\Handler\NullHandler; use Monolog\Handler\NullHandler;
class ContainerTest extends Ion_TestCase { class ContainerTest extends \Ion_TestCase {
public function setUp() public function setUp()
{ {

View File

@ -1,8 +1,11 @@
<?php <?php
use Aviat\Ion\Enum; namespace Aviat\Ion\Tests;
class EnumTest extends Ion_TestCase { use Aviat\Ion\Enum;
use TestEnum;
class EnumTest extends \Ion_TestCase {
protected $expectedConstList = [ protected $expectedConstList = [
'FOO' => 'bar', 'FOO' => 'bar',

View File

@ -1,8 +1,10 @@
<?php <?php
namespace Aviat\Ion\Tests\Exception;
use Aviat\Ion\Exception\DoubleRenderException; use Aviat\Ion\Exception\DoubleRenderException;
class DoubleRenderExceptionTest extends Ion_TestCase { class DoubleRenderExceptionTest extends \Ion_TestCase {
public function testDefaultMessage() public function testDefaultMessage()
{ {

View File

@ -1,13 +1,15 @@
<?php <?php
namespace Aviat\Ion\Tests;
use Aviat\Ion\Friend; use Aviat\Ion\Friend;
class FriendTest extends Ion_TestCase { class FriendTest extends \Ion_TestCase {
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$obj = new FriendTestClass(); $obj = new \FriendTestClass();
$this->friend = new Friend($obj); $this->friend = new Friend($obj);
} }
@ -26,7 +28,7 @@ class FriendTest extends Ion_TestCase {
public function testGet() public function testGet()
{ {
$this->assertEquals(356, $this->friend->protected); $this->assertEquals(356, $this->friend->protected);
$this->assertNull($this->friend->foo); // Return NULL for non-existend properties $this->assertNull($this->friend->foo); // Return NULL for non-existent properties
$this->assertEquals(47, $this->friend->parentProtected); $this->assertEquals(47, $this->friend->parentProtected);
$this->assertEquals(84, $this->friend->grandParentProtected); $this->assertEquals(84, $this->friend->grandParentProtected);
$this->assertNull($this->friend->parentPrivate); // Can't get a parent's privates $this->assertNull($this->friend->parentPrivate); // Can't get a parent's privates
@ -43,14 +45,17 @@ class FriendTest extends Ion_TestCase {
public function testBadInvokation() public function testBadInvokation()
{ {
$this->setExpectedException('InvalidArgumentException', 'Friend must be an object'); $this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Friend must be an object');
$friend = new Friend('foo'); $friend = new Friend('foo');
} }
public function testBadMethod() public function testBadMethod()
{ {
$this->setExpectedException('BadMethodCallException', "Method 'foo' does not exist"); $this->expectException('BadMethodCallException');
$this->expectExceptionMessage("Method 'foo' does not exist");
$this->friend->foo(); $this->friend->foo();
} }
} }

View File

@ -60,11 +60,10 @@ class JsonTest extends \Ion_TestCase {
$this->assertEquals((object)$expected, Json::decode($json, false)); $this->assertEquals((object)$expected, Json::decode($json, false));
$badJson = '{foo:{1|2}}'; $badJson = '{foo:{1|2}}';
$this->setExpectedException( $this->expectException('Aviat\Ion\JsonException');
'Aviat\Ion\JsonException', $this->expectExceptionMessage('JSON_ERROR_SYNTAX - Syntax error');
'JSON_ERROR_SYNTAX - Syntax error', $this->expectExceptionCode(JSON_ERROR_SYNTAX);
JSON_ERROR_SYNTAX
);
Json::decode($badJson); Json::decode($badJson);
} }
} }

View File

@ -1,8 +1,10 @@
<?php <?php
namespace Aviat\Ion\Tests\Model;
use Aviat\Ion\Model\DB as BaseDBModel; use Aviat\Ion\Model\DB as BaseDBModel;
class BaseDBModelTest extends Ion_TestCase { class BaseDBModelTest extends \Ion_TestCase {
public function testBaseDBModelSanity() public function testBaseDBModelSanity()
{ {

View File

@ -1,15 +1,17 @@
<?php <?php
class AbstractTransformerTest extends Ion_TestCase { namespace Aviat\Ion\Tests\Transformer;
class AbstractTransformerTest extends \Ion_TestCase {
protected $transformer; protected $transformer;
public function setUp() public function setUp()
{ {
$this->transformer = new TestTransformer(); $this->transformer = new \TestTransformer();
} }
public function dataTransformCollection() public function dataTransformCollection()
{ {
return [ return [
@ -67,13 +69,13 @@ class AbstractTransformerTest extends Ion_TestCase {
], ],
]; ];
} }
public function testTransform() public function testTransform()
{ {
$data = $this->dataTransformCollection(); $data = $this->dataTransformCollection();
$original = $data['object']['original'][0]; $original = $data['object']['original'][0];
$expected = $data['object']['expected'][0]; $expected = $data['object']['expected'][0];
$actual = $this->transformer->transform($original); $actual = $this->transformer->transform($original);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }

View File

@ -1,7 +1,9 @@
<?php <?php
class ArrayTypeTest extends Ion_TestCase { namespace Aviat\Ion\Tests\Type;
use Aviat\Ion\ArrayWrapper;
class ArrayTypeTest extends \Ion_TestCase {
use \Aviat\Ion\ArrayWrapper;
public function setUp() public function setUp()
@ -124,7 +126,9 @@ class ArrayTypeTest extends Ion_TestCase {
{ {
$obj = $this->arr([]); $obj = $this->arr([]);
$this->setExpectedException('InvalidArgumentException', "Method 'foo' does not exist"); $this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Method 'foo' does not exist");
$obj->foo(); $obj->foo();
} }