From ffaa4a4cab20f2108430d14c1fdeb04061f77567 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 19 Oct 2016 13:24:08 -0400 Subject: [PATCH] Re-namespace tests --- build/header_comment.txt | 3 +- build/update_header_comments.php | 46 +++++++++++-------- composer.json | 7 ++- src/StringWrapper.php | 2 +- tests/BaseModelTest.php | 2 +- tests/Cache/CacheManagerTest.php | 3 +- tests/Cache/Driver/NullDriverTest.php | 3 +- tests/Cache/Driver/RedisDriver2Test.php | 3 +- tests/Cache/Driver/RedisDriverTest.php | 3 +- tests/Cache/Driver/SQLDriverTest.php | 3 +- tests/ConfigTest.php | 2 +- tests/Di/ContainerAwareTest.php | 7 ++- tests/Di/ContainerTest.php | 6 +-- tests/EnumTest.php | 3 +- tests/Exception/DoubleRenderExceptionTest.php | 3 +- tests/FriendTest.php | 5 +- tests/Ion_TestCase.php | 10 ++-- tests/JsonTest.php | 5 +- tests/Model/BaseDBModelTest.php | 3 +- tests/TestSessionHandler.php | 32 +++++++------ tests/Transformer/AbstractTransformerTest.php | 7 ++- tests/Type/ArrayTypeTest.php | 6 ++- tests/View/HtmlViewTest.php | 6 ++- tests/View/HttpViewTest.php | 6 ++- tests/View/JsonViewTest.php | 7 +-- tests/mocks.php | 6 +-- 26 files changed, 110 insertions(+), 79 deletions(-) diff --git a/build/header_comment.txt b/build/header_comment.txt index 4257195..485e85a 100644 --- a/build/header_comment.txt +++ b/build/header_comment.txt @@ -11,4 +11,5 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License * @version 1.0.0 * @link https://git.timshomepage.net/timw4mail/ion - */ \ No newline at end of file + */ + diff --git a/build/update_header_comments.php b/build/update_header_comments.php index 3ae05d1..055357f 100644 --- a/build/update_header_comments.php +++ b/build/update_header_comments.php @@ -25,28 +25,30 @@ if ( ! function_exists('glob_recursive')) function get_text_to_replace($tokens) { - if ($tokens[0][0] !== T_OPEN_TAG) + $output = ''; + + // Tokens have the follow structure if arrays: + // [0] => token type constant + // [1] => raw sytax parsed to that token + // [2] => line number + foreach($tokens as $token) { - return NULL; + // Since we only care about opening docblocks, + // bail out when we get to the namespace token + if (is_array($token) && $token[0] === T_NAMESPACE) + { + break; + } + + if (is_array($token)) + { + $token = $token[1]; + } + + $output .= $token; } - // If there is already a docblock, as the second token after the - // open tag, get the contents of that token to replace - if ($tokens[1][0] === T_DOC_COMMENT) - { - return " 'bar', diff --git a/tests/Exception/DoubleRenderExceptionTest.php b/tests/Exception/DoubleRenderExceptionTest.php index a75caa0..b9ebbbd 100644 --- a/tests/Exception/DoubleRenderExceptionTest.php +++ b/tests/Exception/DoubleRenderExceptionTest.php @@ -17,8 +17,9 @@ namespace Aviat\Ion\Tests\Exception; use Aviat\Ion\Exception\DoubleRenderException; +use Aviat\Ion\Tests\Ion_TestCase; -class DoubleRenderExceptionTest extends \Ion_TestCase { +class DoubleRenderExceptionTest extends Ion_TestCase { public function testDefaultMessage() { diff --git a/tests/FriendTest.php b/tests/FriendTest.php index 916c23a..719b4c8 100644 --- a/tests/FriendTest.php +++ b/tests/FriendTest.php @@ -3,13 +3,14 @@ namespace Aviat\Ion\Tests; use Aviat\Ion\Friend; +use Aviat\Ion\Tests\FriendTestClass; -class FriendTest extends \Ion_TestCase { +class FriendTest extends Ion_TestCase { public function setUp() { parent::setUp(); - $obj = new \FriendTestClass(); + $obj = new FriendTestClass(); $this->friend = new Friend($obj); } diff --git a/tests/Ion_TestCase.php b/tests/Ion_TestCase.php index 875dcff..a75e661 100644 --- a/tests/Ion_TestCase.php +++ b/tests/Ion_TestCase.php @@ -1,15 +1,17 @@ $_SERVER, diff --git a/tests/JsonTest.php b/tests/JsonTest.php index 16a0b66..727fa5a 100644 --- a/tests/JsonTest.php +++ b/tests/JsonTest.php @@ -2,10 +2,9 @@ namespace Aviat\Ion\Tests; -use Aviat\Ion\Json; -use Aviat\Ion\JsonException; +use Aviat\Ion\{Json, JsonException}; -class JsonTest extends \Ion_TestCase { +class JsonTest extends Ion_TestCase { public function testEncode() { diff --git a/tests/Model/BaseDBModelTest.php b/tests/Model/BaseDBModelTest.php index 51fd96a..1a69438 100644 --- a/tests/Model/BaseDBModelTest.php +++ b/tests/Model/BaseDBModelTest.php @@ -17,8 +17,9 @@ namespace Aviat\Ion\Tests\Model; use Aviat\Ion\Model\DB as BaseDBModel; +use Aviat\Ion\Tests\Ion_TestCase; -class BaseDBModelTest extends \Ion_TestCase { +class BaseDBModelTest extends Ion_TestCase { public function testBaseDBModelSanity() { diff --git a/tests/TestSessionHandler.php b/tests/TestSessionHandler.php index 16537a4..e360dc7 100644 --- a/tests/TestSessionHandler.php +++ b/tests/TestSessionHandler.php @@ -1,16 +1,20 @@ save_path/$id"; if (file_exists($file)) @@ -20,13 +24,13 @@ class TestSessionHandler implements SessionHandlerInterface { $this->data[$id] = []; return TRUE; } - + public function gc($maxLifetime) { return TRUE; } - - public function open($save_path, $name) + + public function open($save_path, $name) { /*if ( ! array_key_exists($save_path, $this->data)) { @@ -35,19 +39,19 @@ class TestSessionHandler implements SessionHandlerInterface { }*/ return TRUE; } - - public function read($id) + + public function read($id) { return json_decode(@file_get_contents("$this->save_path/$id"), TRUE); } - - public function write($id, $data) + + public function write($id, $data) { $file = "$this->save_path/$id"; file_put_contents($file, json_encode($data)); - + return TRUE; } - + } // End of TestSessionHandler.php \ No newline at end of file diff --git a/tests/Transformer/AbstractTransformerTest.php b/tests/Transformer/AbstractTransformerTest.php index 5f1905e..9988c44 100644 --- a/tests/Transformer/AbstractTransformerTest.php +++ b/tests/Transformer/AbstractTransformerTest.php @@ -16,14 +16,17 @@ namespace Aviat\Ion\Tests\Transformer; -class AbstractTransformerTest extends \Ion_TestCase { +use Aviat\Ion\Tests\Ion_TestCase; +use Aviat\Ion\Tests\TestTransformer; + +class AbstractTransformerTest extends Ion_TestCase { protected $transformer; public function setUp() { - $this->transformer = new \TestTransformer(); + $this->transformer = new TestTransformer(); } public function dataTransformCollection() diff --git a/tests/Type/ArrayTypeTest.php b/tests/Type/ArrayTypeTest.php index 5b3dc90..4acad36 100644 --- a/tests/Type/ArrayTypeTest.php +++ b/tests/Type/ArrayTypeTest.php @@ -16,9 +16,11 @@ namespace Aviat\Ion\Tests\Type; -class ArrayTypeTest extends \Ion_TestCase { - use \Aviat\Ion\ArrayWrapper; +use Aviat\Ion\ArrayWrapper; +use Aviat\Ion\Tests\Ion_TestCase; +class ArrayTypeTest extends Ion_TestCase { + use ArrayWrapper; public function setUp() { diff --git a/tests/View/HtmlViewTest.php b/tests/View/HtmlViewTest.php index 59c1422..5e355dd 100644 --- a/tests/View/HtmlViewTest.php +++ b/tests/View/HtmlViewTest.php @@ -16,6 +16,10 @@ namespace Aviat\Ion\Tests\View; +use Aviat\Ion\Tests\TestHtmlView; + +use function _dir; + class HtmlViewTest extends HttpViewTest { protected $template_path; @@ -23,7 +27,7 @@ class HtmlViewTest extends HttpViewTest { public function setUp() { parent::setUp(); - $this->view = new \TestHtmlView($this->container); + $this->view = new TestHtmlView($this->container); } public function testRenderTemplate() diff --git a/tests/View/HttpViewTest.php b/tests/View/HttpViewTest.php index afe82cd..d6f6d0a 100644 --- a/tests/View/HttpViewTest.php +++ b/tests/View/HttpViewTest.php @@ -18,8 +18,10 @@ namespace Aviat\Ion\Tests\View; use Aviat\Ion\Friend; use Aviat\Ion\Exception\DoubleRenderException; +use Aviat\Ion\Tests\Ion_TestCase; +use Aviat\Ion\Tests\TestHttpView; -class HttpViewTest extends \Ion_TestCase { +class HttpViewTest extends Ion_TestCase { protected $view; protected $friend; @@ -27,7 +29,7 @@ class HttpViewTest extends \Ion_TestCase { public function setUp() { parent::setUp(); - $this->view = new \TestHttpView($this->container); + $this->view = new TestHttpView($this->container); $this->friend = new Friend($this->view); } diff --git a/tests/View/JsonViewTest.php b/tests/View/JsonViewTest.php index 05716fc..5a9874c 100644 --- a/tests/View/JsonViewTest.php +++ b/tests/View/JsonViewTest.php @@ -17,6 +17,7 @@ namespace Aviat\Ion\Tests\View; use Aviat\Ion\Friend; +use Aviat\Ion\Tests\TestJsonView; class JsonViewTest extends HttpViewTest { @@ -24,14 +25,14 @@ class JsonViewTest extends HttpViewTest { { parent::setUp(); - $this->view = new \TestJsonView($this->container); + $this->view = new TestJsonView($this->container); $this->friend = new Friend($this->view); } public function testSetOutputJSON() { // Extend view class to remove destructor which does output - $view = new \TestJsonView($this->container); + $view = new TestJsonView($this->container); // Json encode non-string $content = ['foo' => 'bar']; @@ -43,7 +44,7 @@ class JsonViewTest extends HttpViewTest { public function testSetOutput() { // Directly set string - $view = new \TestJsonView($this->container); + $view = new TestJsonView($this->container); $content = '{}'; $expected = '{}'; $view->setOutput($content); diff --git a/tests/mocks.php b/tests/mocks.php index b83fcf5..5ba55aa 100644 --- a/tests/mocks.php +++ b/tests/mocks.php @@ -3,14 +3,14 @@ * All the mock classes that extend the classes they are used to test */ +namespace Aviat\Ion\Tests; + use Aviat\Ion\Enum; use Aviat\Ion\Exception\DoubleRenderException; use Aviat\Ion\Friend; use Aviat\Ion\Transformer\AbstractTransformer; use Aviat\Ion\View; -use Aviat\Ion\View\HtmlView; -use Aviat\Ion\View\HttpView; -use Aviat\Ion\View\JsonView; +use Aviat\Ion\View\{HtmlView, HttpView, JsonView}; // ----------------------------------------------------------------------------- // Mock the default error handler