Re-namespace tests
This commit is contained in:
parent
258ebf30ef
commit
ffaa4a4cab
@ -12,3 +12,4 @@
|
||||
* @version 1.0.0
|
||||
* @link https://git.timshomepage.net/timw4mail/ion
|
||||
*/
|
||||
|
||||
|
@ -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 "<?php\n" . $tokens[1][1];
|
||||
}
|
||||
// If there is a declare strict types,
|
||||
else if ($tokens[1][0] === T_DECLARE && $tokens[9][0] === T_DOC_COMMENT)
|
||||
{
|
||||
// '<?php' and 'declare(strict_types=1);' makes for 8 tokens
|
||||
// replace it all
|
||||
return "<?php\ndeclare(strict_types=1);\n" . $tokens[9][1];
|
||||
}
|
||||
else if ($tokens[1][0] !== T_DOC_COMMENT)
|
||||
{
|
||||
return "<?php";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function get_tokens($source)
|
||||
@ -59,6 +61,12 @@ function replace_files(array $files, $template)
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$source = file_get_contents($file);
|
||||
|
||||
if (stripos($source, 'namespace') === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$tokens = get_tokens($source);
|
||||
$text_to_replace = get_text_to_replace($tokens);
|
||||
|
||||
|
@ -34,14 +34,13 @@
|
||||
"humbug/humbug": "~1.0@dev",
|
||||
"consolidation/robo": "~1.0@RC",
|
||||
"henrikbjorn/lurker": "^1.1.0",
|
||||
"nikic/php-parser": "3.0.*@alpha",
|
||||
"nikic/php-parser": "3.0.*@beta",
|
||||
"monolog/monolog": "1.*",
|
||||
"predis/predis": "1.1.*",
|
||||
"squizlabs/php_codesniffer": "^3.0.0@alpha"
|
||||
"squizlabs/php_codesniffer": "^3.0.0@RC"
|
||||
},
|
||||
"suggest": {
|
||||
"monolog/monolog": "Provides implementation of psr/log",
|
||||
"predis/predis": "Required for redis cache driver",
|
||||
"zendframework/zend-diactoros": "Provides implementation of psr/http-message"
|
||||
"predis/predis": "Required for redis cache driver"
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ trait StringWrapper {
|
||||
* @param string $str
|
||||
* @return StringType
|
||||
*/
|
||||
public function string($str)
|
||||
public function string($str): StringType
|
||||
{
|
||||
return StringType::create($str);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aviat\Ion\Model as BaseModel;
|
||||
|
||||
class BaseModelTest extends \Ion_TestCase {
|
||||
class BaseModelTest extends Ion_TestCase {
|
||||
|
||||
public function testBaseModelSanity()
|
||||
{
|
||||
|
@ -18,8 +18,9 @@ namespace Aviat\Ion\Tests\Cache;
|
||||
|
||||
use Aviat\Ion\Friend;
|
||||
use Aviat\Ion\Cache\CacheManager;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
|
||||
class CacheManagerTest extends \Ion_TestCase {
|
||||
class CacheManagerTest extends Ion_TestCase {
|
||||
|
||||
protected $cachedTime;
|
||||
|
||||
|
@ -17,8 +17,9 @@
|
||||
namespace Aviat\Ion\Tests\Cache\Driver;
|
||||
|
||||
use Aviat\Ion\Cache\Driver\NullDriver;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
|
||||
class CacheNullDriverTest extends \Ion_TestCase {
|
||||
class CacheNullDriverTest extends Ion_TestCase {
|
||||
use CacheDriverBase;
|
||||
|
||||
protected $driver;
|
||||
|
@ -18,8 +18,9 @@ namespace Aviat\Ion\Tests\Cache\Driver;
|
||||
|
||||
use Aviat\Ion\Config;
|
||||
use Aviat\Ion\Cache\Driver\RedisDriver;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
|
||||
class CacheRedisDriverTestTwo extends \Ion_TestCase {
|
||||
class CacheRedisDriverTestTwo extends Ion_TestCase {
|
||||
use CacheDriverBase;
|
||||
|
||||
protected $driver;
|
||||
|
@ -17,8 +17,9 @@
|
||||
namespace Aviat\Ion\Tests\Cache\Driver;
|
||||
|
||||
use Aviat\Ion\Cache\Driver\RedisDriver;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
|
||||
class CacheRedisDriverTest extends \Ion_TestCase {
|
||||
class CacheRedisDriverTest extends Ion_TestCase {
|
||||
use CacheDriverBase;
|
||||
|
||||
protected $driver;
|
||||
|
@ -19,8 +19,9 @@ namespace Aviat\Ion\Tests\Cache\Driver;
|
||||
use Aviat\Ion\Config;
|
||||
use Aviat\Ion\Friend;
|
||||
use Aviat\Ion\Cache\Driver\SQLDriver;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
|
||||
class CacheSQLDriverTest extends \Ion_TestCase {
|
||||
class CacheSQLDriverTest extends Ion_TestCase {
|
||||
use CacheDriverBase;
|
||||
|
||||
protected $driver;
|
||||
|
@ -4,7 +4,7 @@ namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aviat\Ion\Config;
|
||||
|
||||
class ConfigTest extends \Ion_TestCase {
|
||||
class ConfigTest extends Ion_TestCase {
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
@ -16,10 +16,9 @@
|
||||
|
||||
namespace Aviat\Ion\Tests\Di;
|
||||
|
||||
use Aviat\Ion\Di\Container;
|
||||
use Aviat\Ion\Di\ContainerAware;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\{Container, ContainerAware, ContainerInterface};
|
||||
use Aviat\Ion\Di\Exception\ContainerException;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
|
||||
class Aware {
|
||||
use ContainerAware;
|
||||
@ -31,7 +30,7 @@ class Aware {
|
||||
}
|
||||
|
||||
|
||||
class ContainerAwareTest extends \Ion_TestCase {
|
||||
class ContainerAwareTest extends Ion_TestCase {
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
@ -18,9 +18,9 @@ namespace Aviat\Ion\Tests\Di;
|
||||
|
||||
use Aviat\Ion\Di\Container;
|
||||
use Aviat\Ion\Di\Exception\ContainerException;
|
||||
use Aviat\Ion\Tests\Ion_TestCase;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\{TestHandler, NullHandler};
|
||||
|
||||
class FooTest {
|
||||
|
||||
@ -35,7 +35,7 @@ class FooTest2 {
|
||||
use \Aviat\Ion\Di\ContainerAware;
|
||||
}
|
||||
|
||||
class ContainerTest extends \Ion_TestCase {
|
||||
class ContainerTest extends Ion_TestCase {
|
||||
|
||||
|
||||
public function setUp()
|
||||
|
@ -3,9 +3,8 @@
|
||||
namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aviat\Ion\Enum;
|
||||
use TestEnum;
|
||||
|
||||
class EnumTest extends \Ion_TestCase {
|
||||
class EnumTest extends Ion_TestCase {
|
||||
|
||||
protected $expectedConstList = [
|
||||
'FOO' => 'bar',
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Aviat\Ion\Tests;
|
||||
|
||||
use Aura\Web\WebFactory;
|
||||
use Aviat\Ion\Json;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\Diactoros\Response as HttpResponse;
|
||||
|
||||
use Aviat\Ion\Json;
|
||||
|
||||
define('ROOT_DIR', realpath(__DIR__ . '/../') . '/');
|
||||
define('SRC_DIR', ROOT_DIR . 'src/');
|
||||
define('TEST_DATA_DIR', __DIR__ . '/test_data');
|
||||
@ -18,7 +20,7 @@ define('TEST_VIEW_DIR', __DIR__ . '/test_views');
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
class Ion_TestCase extends PHPUnit_Framework_TestCase {
|
||||
class Ion_TestCase extends TestCase {
|
||||
// Test directory constants
|
||||
const ROOT_DIR = ROOT_DIR;
|
||||
const SRC_DIR = SRC_DIR;
|
||||
@ -102,7 +104,7 @@ class Ion_TestCase extends PHPUnit_Framework_TestCase {
|
||||
* @param array $supers
|
||||
* @return void
|
||||
*/
|
||||
public function setSuperGlobals($supers = [])
|
||||
public function setSuperGlobals(array $supers = [])
|
||||
{
|
||||
$default = [
|
||||
'_SERVER' => $_SERVER,
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Aviat\Ion\Tests;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
|
||||
class TestSessionHandler implements SessionHandlerInterface {
|
||||
|
||||
public $data = [];
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user