diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4c36e38
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.idea/
+vendor/
diff --git a/.travis.yml b/.travis.yml
index a568080..9f553f5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,6 @@
language: php
php:
- - 5.4
- - 5.5
- - 5.6
- - hhvm
+ - '7.2'
install:
- phpenv rehash
- travis_retry composer self-update
diff --git a/composer.json b/composer.json
index 0fbd21c..a9ebc0c 100644
--- a/composer.json
+++ b/composer.json
@@ -3,9 +3,9 @@
"homepage": "http://github.com/c9s/ClassTemplate",
"description": "Class template Utilities",
"require": {
- "php": ">=5.3.0",
- "corneltek/codegen": "^2",
- "twig/twig": "^1"
+ "php": ">=7.2",
+ "corneltek/codegen": "^3.2",
+ "twig/twig": "^2.11|^1.42"
},
"require-dev": {
"corneltek/phpunit-testmore": "dev-master"
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..86b99e3
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,344 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "f96e0b10712537168e026da80c6c6bb7",
+ "packages": [
+ {
+ "name": "corneltek/codegen",
+ "version": "3.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/c9s/CodeGen.git",
+ "reference": "aa1964de6ab5810f13c4e8f1ccaa5fb0305626ed"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/c9s/CodeGen/zipball/aa1964de6ab5810f13c4e8f1ccaa5fb0305626ed",
+ "reference": "aa1964de6ab5810f13c4e8f1ccaa5fb0305626ed",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/inflector": "*",
+ "php": ">=5.3.0",
+ "twig/twig": "^2|~1.32.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.2.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "CodeGen\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Yo-An Lin",
+ "email": "yoanlin93@gmail.com"
+ }
+ ],
+ "description": "PHP Code Generation Library",
+ "homepage": "http://github.com/c9s/CodeGen",
+ "time": "2017-05-18T15:38:22+00:00"
+ },
+ {
+ "name": "doctrine/inflector",
+ "version": "v1.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/inflector.git",
+ "reference": "5527a48b7313d15261292c149e55e26eae771b0a"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a",
+ "reference": "5527a48b7313d15261292c149e55e26eae771b0a",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^6.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Roman Borschel",
+ "email": "roman@code-factory.org"
+ },
+ {
+ "name": "Benjamin Eberlei",
+ "email": "kontakt@beberlei.de"
+ },
+ {
+ "name": "Guilherme Blanco",
+ "email": "guilhermeblanco@gmail.com"
+ },
+ {
+ "name": "Jonathan Wage",
+ "email": "jonwage@gmail.com"
+ },
+ {
+ "name": "Johannes Schmitt",
+ "email": "schmittjoh@gmail.com"
+ }
+ ],
+ "description": "Common String Manipulations with regard to casing and singular/plural rules.",
+ "homepage": "http://www.doctrine-project.org",
+ "keywords": [
+ "inflection",
+ "pluralize",
+ "singularize",
+ "string"
+ ],
+ "time": "2018-01-09T20:05:19+00:00"
+ },
+ {
+ "name": "symfony/polyfill-ctype",
+ "version": "v1.12.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/polyfill-ctype.git",
+ "reference": "550ebaac289296ce228a706d0867afc34687e3f4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4",
+ "reference": "550ebaac289296ce228a706d0867afc34687e3f4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-ctype": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.12-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Polyfill\\Ctype\\": ""
+ },
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Gert de Pagter",
+ "email": "BackEndTea@gmail.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for ctype functions",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "ctype",
+ "polyfill",
+ "portable"
+ ],
+ "time": "2019-08-06T08:03:45+00:00"
+ },
+ {
+ "name": "symfony/polyfill-mbstring",
+ "version": "v1.12.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/polyfill-mbstring.git",
+ "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17",
+ "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-mbstring": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.12-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ },
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for the Mbstring extension",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "mbstring",
+ "polyfill",
+ "portable",
+ "shim"
+ ],
+ "time": "2019-08-06T08:03:45+00:00"
+ },
+ {
+ "name": "twig/twig",
+ "version": "v2.11.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/twigphp/Twig.git",
+ "reference": "699ed2342557c88789a15402de5eb834dedd6792"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/twigphp/Twig/zipball/699ed2342557c88789a15402de5eb834dedd6792",
+ "reference": "699ed2342557c88789a15402de5eb834dedd6792",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.0",
+ "symfony/polyfill-ctype": "^1.8",
+ "symfony/polyfill-mbstring": "^1.3"
+ },
+ "require-dev": {
+ "psr/container": "^1.0",
+ "symfony/debug": "^2.7",
+ "symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.11-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Twig_": "lib/"
+ },
+ "psr-4": {
+ "Twig\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "role": "Lead Developer",
+ "email": "fabien@symfony.com",
+ "homepage": "http://fabien.potencier.org"
+ },
+ {
+ "name": "Armin Ronacher",
+ "role": "Project Founder",
+ "email": "armin.ronacher@active-4.com"
+ },
+ {
+ "name": "Twig Team",
+ "role": "Contributors",
+ "homepage": "https://twig.symfony.com/contributors"
+ }
+ ],
+ "description": "Twig, the flexible, fast, and secure template language for PHP",
+ "homepage": "https://twig.symfony.com",
+ "keywords": [
+ "templating"
+ ],
+ "time": "2019-06-18T15:37:11+00:00"
+ }
+ ],
+ "packages-dev": [
+ {
+ "name": "corneltek/phpunit-testmore",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/c9s/PHPUnit_TestMore.git",
+ "reference": "1b3728bfbc23c7ac89836fbec9a0b2aab6be8c9f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/c9s/PHPUnit_TestMore/zipball/1b3728bfbc23c7ac89836fbec9a0b2aab6be8c9f",
+ "reference": "1b3728bfbc23c7ac89836fbec9a0b2aab6be8c9f",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "autoload": {
+ "files": [
+ "TestMore.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "time": "2017-03-09T16:13:38+00:00"
+ }
+ ],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": {
+ "corneltek/phpunit-testmore": 20
+ },
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": {
+ "php": ">=7.1"
+ },
+ "platform-dev": []
+}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d8b1f78..b94c3c1 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -25,11 +25,7 @@
@@ -37,8 +33,7 @@
target="build/logs/clover.xml"/>
+ target="build/logs/junit.xml"/>
diff --git a/src/ClassTemplate/ClassFile.php b/src/ClassTemplate/ClassFile.php
index 6a61ffe..2eec9be 100644
--- a/src/ClassTemplate/ClassFile.php
+++ b/src/ClassTemplate/ClassFile.php
@@ -1,10 +1,9 @@
render());
}
-
}
diff --git a/src/ClassTemplate/TemplateClassFile.php b/src/ClassTemplate/TemplateClassFile.php
index d7baa25..cab833d 100644
--- a/src/ClassTemplate/TemplateClassFile.php
+++ b/src/ClassTemplate/TemplateClassFile.php
@@ -1,11 +1,9 @@
return = false;
- return $ser->encode( $obj );
-}
+use Twig\Environment;
+use Twig\Loader\FilesystemLoader;
class TemplateView
{
private $loader;
private $twig;
-
public $stash = array();
- public $overwrite = false;
public function __construct( $dirs , $options = array(), $stash = array() )
{
- $this->loader = new \Twig_Loader_Filesystem( $dirs );
- $this->twig = new \Twig_Environment($this->loader, array(
+ $this->loader = new FilesystemLoader( $dirs );
+ $this->twig = new Environment($this->loader, array(
'cache' => false,
'auto_reload' => true,
'autoescape' => false,
'debug' => true,
) + $options );
$this->stash = $stash;
- $this->twig->addFilter(new Twig_SimpleFilter('export','\ClassTemplate\twig_var_export'));
}
public function __set($n,$v)
@@ -46,9 +35,7 @@ public function __get($n)
public function renderFile($file)
{
- $template = $this->twig->loadTemplate($file);
- return $template->render( $this->stash );
+ return $this->twig->load($file)->render($this->stash);
}
-
}
diff --git a/tests/ClassTemplate/ClassDeclareTest.php b/tests/ClassTemplate/ClassDeclareTest.php
index 9f0f270..f1ffdbf 100644
--- a/tests/ClassTemplate/ClassDeclareTest.php
+++ b/tests/ClassTemplate/ClassDeclareTest.php
@@ -8,7 +8,7 @@ class ClassFileTest extends CodeGenTestCase
public function testUse()
{
$use = new UseClass('\Foo\Bar');
- is( 'Foo\Bar', $use->class );
+ $this->assertCodeEquals('use Foo\Bar;', $use);
}
public function testClassTemplateWithDefaultOptions()
@@ -36,7 +36,7 @@ public function testClassTemplate()
'template' => 'Class.php.twig',
'template_dirs' => array('src/ClassTemplate/Templates'),
));
- ok($classTemplate);
+ $this->assertTrue($classTemplate);
$classTemplate->addProperty('record','Product');
$classTemplate->addProperty('fields', array('lang', 'name'));
$classTemplate->addMethod('public','getTwo',array(),'return 2;');
@@ -44,19 +44,19 @@ public function testClassTemplate()
$this->evalTemplate($classTemplate);
- ok(class_exists($classTemplate->class->getFullName()));
+ $this->assertTrue(class_exists($classTemplate->class->getFullName()));
$bar22 = new Foo\Bar1;
- ok($bar22);
+ $this->assertTrue($bar22);
- is('Product', $bar22->record);
- is(array('lang','name'), $bar22->fields);
+ $this->assertEquals('Product', $bar22->record);
+ $this->assertEquals(array('lang','name'), $bar22->fields);
- ok(method_exists($bar22,'getTwo'));
- ok(method_exists($bar22,'getFoo'));
+ $this->assertTrue(method_exists($bar22,'getTwo'));
+ $this->assertTrue(method_exists($bar22,'getFoo'));
- is(2,$bar22->getTwo());
+ $this->assertEquals(2,$bar22->getTwo());
- is(3,$bar22->getFoo(3));
+ $this->assertEquals(3,$bar22->getFoo(3));
}
}
diff --git a/tests/ClassTemplate/ClassDeclareTraitTest.php b/tests/ClassTemplate/ClassDeclareTraitTest.php
index 01f92de..8b89d68 100644
--- a/tests/ClassTemplate/ClassDeclareTraitTest.php
+++ b/tests/ClassTemplate/ClassDeclareTraitTest.php
@@ -49,9 +49,9 @@ public function testTraitUseAs() {
$this->evalTemplate($classTemplate);
$foo = new Foo\TraitUseAsTest;
- ok($foo);
- is('hello from A',$foo->talk());
- is('hello from B',$foo->hello());
+ $this->assertTrue($foo);
+ $this->assertEquals('hello from A',$foo->talk());
+ $this->assertEquals('hello from B',$foo->hello());
}
}
diff --git a/tests/ClassTemplate/ClassInjectionTest.php b/tests/ClassTemplate/ClassInjectionTest.php
index 064f4db..0bb5a0c 100644
--- a/tests/ClassTemplate/ClassInjectionTest.php
+++ b/tests/ClassTemplate/ClassInjectionTest.php
@@ -1,6 +1,8 @@
assertTrue($foo);
$inject = new ClassTemplate\ClassInjection($foo);
- ok($inject);
+ $this->assertTrue($inject);
$inject->read();
@@ -35,20 +37,20 @@ function getValue() {
$inject->write();
// file_put_contents('tests/data/injected', $inject);
- is( file_get_contents('tests/data/injected'), $inject->__toString() );
+ $this->assertEquals( file_get_contents('tests/data/injected'), $inject->__toString() );
$inject->read();
- is( file_get_contents('tests/data/injected'), $inject->__toString() );
+ $this->assertEquals( file_get_contents('tests/data/injected'), $inject->__toString() );
$inject->write();
- is( file_get_contents('tests/data/injected'), $inject->__toString() );
+ $this->assertEquals( file_get_contents('tests/data/injected'), $inject->__toString() );
$inject->replaceContent('');
$inject->write();
// file_put_contents('tests/data/replaced',$inject);
- is( file_get_contents('tests/data/replaced'), $inject->__toString() );
+ $this->assertEquals( file_get_contents('tests/data/replaced'), $inject->__toString() );
// TODO test the content
diff --git a/tests/data/class_simple.fixture b/tests/data/class_simple.fixture
index 5edfa0a..2b31bfa 100644
--- a/tests/data/class_simple.fixture
+++ b/tests/data/class_simple.fixture
@@ -1,16 +1,22 @@
'lang',
1 => 'name',
);
+
public function getTwo()
{
return 2;
}
+
public function getFoo($i)
{
return $i;