diff --git a/.gitignore b/.gitignore index 2e24252..347265d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .idea/ build/ vendor/ -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index 8a325cb..44d2891 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ after_script: - if [ $TRAVIS_PHP_VERSION = '7.2' ]; then php vendor/bin/coveralls; fi after_success: - - travis_retry php vendor/bin/coveralls -v \ No newline at end of file + - travis_retry php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index e7d2582..4e3f0ea 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ "selami/stdlib": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^8.0", "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpcov": "^5.0", + "phpunit/phpcov": "^6.0", "zendframework/zend-servicemanager":"~3.3", "twig/twig": "^2.6", "twig/extensions": "^1.5" @@ -35,5 +35,10 @@ "Selami\\View\\Twig\\": "src/Twig/", "Selami\\View\\Twig\\Functions\\": "src/Twig/Functions" } + }, + "autoload-dev": { + "psr-4": { + "TwigTests\\": "test/" + } } } diff --git a/test/TwigTest/TwigTest.php b/test/TwigTest/TwigTest.php index 8f4576a..3abe469 100644 --- a/test/TwigTest/TwigTest.php +++ b/test/TwigTest/TwigTest.php @@ -1,16 +1,15 @@ [ @@ -28,7 +27,7 @@ class myTwigClass extends TestCase 'title' => 'Twig::test', ] ], - 'app_namespace' => 'TwigTest', + 'app_namespace' => 'TwigTests', 'templates_path' => __DIR__ . '/templates', 'cache_dir' => '/tmp', 'title' => 'Twig::test', @@ -41,7 +40,7 @@ class myTwigClass extends TestCase private $view; - public function setUp() + protected function setUp(): void { $container = new ServiceManager(); @@ -63,18 +62,18 @@ public function setUp() public function shouldRenderHtmlAndAddGlobalsSuccessfully() { $this->view->addGlobal('add_global', 'ok'); - $result = $this->view->render('main.twig', ['app' => ['name' => 'myTwigClassTest']]); - $this->assertContains( + $result = $this->view->render('main.twig', ['app' => ['name' => TwigTest::class]]); + $this->assertStringContainsString( 'ok', $result, 'Twig didn\'t correctly render and add globals.' ); - $this->assertContains( + $this->assertStringContainsString( '1', $result, 'Twig didn\'t correctly render and add globals.' ); - $this->assertContains('Twig::test', $result, "Twig didn't correctly render and add globals."); + $this->assertStringContainsString('Twig::test', $result, "Twig didn't correctly render and add globals."); } @@ -85,8 +84,8 @@ public function shouldRenderHtmlAndAddGlobalsSuccessfully() public function shouldExtendForGetUrlSuccessfully() { $result = $this->view->render('get_url.twig', ['loaded_language' => 'tr_TR']); - $this->assertContains('http://127.0.0.1/logout', $result, "Twig didn't correctly get url."); - $this->assertContains('http://127.0.0.1/tr_TR/about', $result, "Twig didn't correctly get url."); + $this->assertStringContainsString('http://127.0.0.1/logout', $result, "Twig didn't correctly get url."); + $this->assertStringContainsString('http://127.0.0.1/tr_TR/about', $result, "Twig didn't correctly get url."); } @@ -96,8 +95,8 @@ public function shouldExtendForGetUrlSuccessfully() public function shouldExtendForTranslatorSuccessfully() { $result = $this->view->render('translation.twig'); - $this->assertContains('Merhaba Selami', $result, "Twig didn't correctly translate."); - $this->assertContains('Text missing in dictionary', $result, "Twig didn't correctly translate."); + $this->assertStringContainsString('Merhaba Selami', $result, "Twig didn't correctly translate."); + $this->assertStringContainsString('Text missing in dictionary', $result, "Twig didn't correctly translate."); } /** @@ -106,8 +105,8 @@ public function shouldExtendForTranslatorSuccessfully() public function shouldExtendForQueryParamsSuccessfully() { $result = $this->view->render('query_params.twig', ['parameters' => $this->config['runtime']['query_parameters']]); - $this->assertContains('?param1=1¶m2=2¶m3=3', $result, "Twig didn't correctly build http query."); - $this->assertContains('?controller=login¶m1=1¶m2=2¶m3=3', $result, "Twig didn't correctly build http query."); + $this->assertStringContainsString('?param1=1¶m2=2¶m3=3', $result, "Twig didn't correctly build http query."); + $this->assertStringContainsString('?controller=login¶m1=1¶m2=2¶m3=3', $result, "Twig didn't correctly build http query."); } /** @@ -116,8 +115,8 @@ public function shouldExtendForQueryParamsSuccessfully() public function shouldExtendForSiteUrlSuccessfully() { $result = $this->view->render('site_url.twig', ['parameters' => $this->config['runtime']['query_parameters']]); - $this->assertContains('http://127.0.0.1', $result, "Twig didn't correctly return base_url."); - $this->assertContains('http://127.0.0.1/login', $result, "Twig didn't correctly return base_url."); + $this->assertStringContainsString('http://127.0.0.1', $result, "Twig didn't correctly return base_url."); + $this->assertStringContainsString('http://127.0.0.1/login', $result, "Twig didn't correctly return base_url."); } /** @@ -126,10 +125,10 @@ public function shouldExtendForSiteUrlSuccessfully() public function shouldExtendForVarDumpSuccessfully() { $result = $this->view->render('var_dump.twig', ['parameters' => $this->config['runtime']['query_parameters']]); - $this->assertContains('array(3)', $result, "Twig didn't correctly dump variable."); - $this->assertContains('param1', $result, "Twig didn't correctly dump variable."); - $this->assertContains('param2', $result, "Twig didn't correctly dump variable."); - $this->assertContains('param3', $result, "Twig didn't correctly dump variable."); + $this->assertStringContainsString('array(3)', $result, "Twig didn't correctly dump variable."); + $this->assertStringContainsString('param1', $result, "Twig didn't correctly dump variable."); + $this->assertStringContainsString('param2', $result, "Twig didn't correctly dump variable."); + $this->assertStringContainsString('param3', $result, "Twig didn't correctly dump variable."); } /** @@ -144,20 +143,18 @@ public function shouldExtendForPaginationSuccessfully() ]; $expected = ''; $result = $this->view->render('pagination.twig', $data); - $this->assertContains($expected, $result, "Twig didn't correctly return pagination."); + $this->assertStringContainsString($expected, $result, "Twig didn't correctly return pagination."); } /** * @test - * @expectedException Twig_Error_Runtime */ public function shouldExtendForWidgetsSuccessfully() { - $result = $this->view->render('widgets.twig', ['parameters' => $this->config['runtime']['query_parameters']]); - $this->assertContains('top', $result, "Twig didn't correctly return widget."); - $this->assertContains('top1', $result, "Twig didn't correctly return widget."); - $this->assertContains('top2', $result, "Twig didn't correctly return widget."); + $this->expectException(RuntimeError::class); + + $this->view->render('widgets.twig', ['parameters' => $this->config['runtime']['query_parameters']]); } /** @@ -166,8 +163,8 @@ public function shouldExtendForWidgetsSuccessfully() public function shouldRenderWidgetFromAnotherSourcesSuccessfully() { $this->view->addGlobal('add_global', '{{Widget_menu_top()}}'); - $result = $this->view->render('main.twig', ['app' => ['name' => 'myTwigClassTest']]); + $result = $this->view->render('main.twig', ['app' => ['name' => TwigTest::class]]); - $this->assertContains('topassertStringContainsString('topadd('test', dirname(__DIR__)); -$loader->register(); diff --git a/test/common/widgets/Menu.php b/test/common/widgets/Menu.php index 2b08be3..e7a20a0 100644 --- a/test/common/widgets/Menu.php +++ b/test/common/widgets/Menu.php @@ -1,6 +1,6 @@