/* global describe, run */
var language = 'php';
describe(language, function() {
run(
language,
'echo',
'echo \'hello world\';',
'echo \'hello world\';'
);
run(
language,
'variable',
'$foo = true;',
'$foo = true;'
);
skip(
language,
'variable variable',
'$$foo = true;',
'$$foo = true;'
);
run(
language,
'string concatenation',
"$foo = 'test' . 'string' . 'concatenation';",
'$foo = \'test\' . \'string\' . \'concatenation\';'
);
run(
language,
'include 1',
"include 'App.php';",
'include \'App.php\';'
);
run(
language,
'include 2',
"include_once('App.php');",
'include_once(\'App.php\');'
);
run(
language,
'instanceof',
"$is_array_object = $collection instanceof ArrayObject;",
'$is_array_object = $collection instanceof ArrayObject;'
);
run(
language,
'instanceof namespace class',
"$is_user = $object instanceof App\\User;",
'$is_user = $object instanceof App\\User;'
);
run(
language,
'array stuff',
'$turtles = array(\n' +
' \'leonardo\',\n' +
' \'michaelangelo\',\n' +
' \'donatello\',\n' +
' \'raphael\'\n' +
');\n' +
'\n' +
'$exists = array_key_exists(0, $turtles);',
'$turtles = array(\n' +
' \'leonardo\',\n' +
' \'michaelangelo\',\n' +
' \'donatello\',\n' +
' \'raphael\'\n' +
');\n' +
'\n' +
'$exists = array_key_exists(0, $turtles);'
);
run(
language,
'php tag',
'<?php echo $foo; ?>',
'<?php echo $foo; ?>'
);
run(
language,
'php tag 2',
'<?php echo \'?>\'; ?>',
'<?php echo \'?>\'; ?>'
);
run(
language,
'namespace declaration',
'namespace Sonic\\Database;',
'namespace Sonic\\Database;'
);
run(
language,
'use declaration',
'use Sonic;',
'use Sonic;'
);
run(
language,
'class declaration',
'class MyClass {}',
'class MyClass {}'
);
run(
language,
'trait declaration',
'trait MyClass {}',
'trait MyClass {}'
);
run(
language,
'interface declaration',
'interface IMyClass {}',
'interface IMyClass {}'
);
run(
language,
'abstract class declaration',
'abstract class MyClass {}',
'abstract class MyClass {}'
);
run(
language,
'final class declaration',
'final class TestClass\n' +
'{\n' +
'}',
'final class TestClass\n' +
'{\n' +
'}'
);
run(
language,
'class with an implementation declaration',
'class Collection implements IList {}',
'class Collection implements IList {}'
);
run(
language,
'child class declaration',
'class Collection extends ArrayObject {}',
'class Collection extends ArrayObject {}'
);
run(
language,
'child class with an implementation declaration',
'class Collection extends ArrayObject implements IList {}',
'class Collection extends ArrayObject implements IList {}'
);
run(
language,
'final child class declaration',
'final class TestClass extends \\Some\\Other\\Class {}',
'final class TestClass extends \\Some\\Other\\Class {}'
);
run(
language,
'test static',
'self::_doSomething();\n' +
'static::_doSomethingElse();',
'self::_doSomething();\n' +
'static::_doSomethingElse();'
);
run(
language,
'test magic function',
'function __autoload($class)\n' +
'{\n' +
' // do whatever\n' +
'}',
'function __autoload($class)\n' +
'{\n' +
' \n' +
'}'
);
run(
language,
'test magic method',
'class SomeThing\n' +
'{\n' +
' protected $_foo;\n' +
'\n' +
' public function __construct($foo)\n' +
' {\n' +
' $this->_foo = $foo;\n' +
' }\n' +
'}',
'class SomeThing\n' +
'{\n' +
' protected $_foo;\n' +
'\n' +
' public function __construct($foo)\n' +
' {\n' +
' $this->_foo = $foo;\n' +
' }\n' +
'}'
);
run(
language,
'test new class',
'new SomeClass();',
'new SomeClass();'
);
run(
language,
'test new namespace class',
'new Sonic\\Database\\Query();',
'new Sonic\\Database\\Query();'
);
run(
language,
'test new class without parenthesis',
'new Sonic\\Controller;',
'new Sonic\\Controller;'
);
run(
language,
'test static class call',
'$path = Sonic\\App::getInstance()->getPath();',
'$path = Sonic\\App::getInstance()->getPath();'
);
run(
language,
'constant language',
'true; TRUE;',
'true; TRUE;'
);
run(
language,
'constant',
'TEST_CONSTANT',
'TEST_CONSTANT'
);
run(
language,
'constant 2',
'(TEST_CONSTANT_2)',
'(TEST_CONSTANT_2)'
);
run(
language,
'class constant',
'$version = Sonic\\App::VERSION',
'$version = Sonic\\App::VERSION'
);
run(
language,
'static variable access',
'$foo = Sonic\\App::$static_property;',
'$foo = Sonic\\App::$static_property;'
);
run(
language,
'type hint',
'public static function getForUser(User $user, Sort $sort) {}',
'public static function getForUser(User $user, Sort $sort) {}'
);
run(
language,
'type hint with namespace',
'public static function getForUser(\\SomeApp\\User $user) {}',
'public static function getForUser(\\SomeApp\\User $user) {}'
);
});