Skip to content

Commit

Permalink
Update to Codeception 5 (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed May 3, 2022
1 parent d1ed1c4 commit e3a93ee
Show file tree
Hide file tree
Showing 28 changed files with 102 additions and 186 deletions.
6 changes: 4 additions & 2 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace: App\Tests
support_namespace: Support
paths:
tests: tests
output: runtime/tests/_output
data: runtime/tests/_data
support: tests/_support
data: tests/Support/Data
support: tests/Support
envs: tests/_envs
actor_suffix: Tester
extensions:
Expand All @@ -20,3 +21,4 @@ coverage:
- src/*
exclude:
- src/Asset/*
- src/Installer.php
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
},
"require-dev": {
"codeception/c3": "^2.6",
"codeception/codeception": "^4.1",
"codeception/codeception": "^5.0",
"codeception/module-asserts": "^2.0",
"codeception/module-cli": "^2.0",
"codeception/module-phpbrowser": "^2.0",
"phpunit/phpunit": "^9.5",
"roave/infection-static-analysis-plugin": "^1.16",
"roave/security-advisories": "dev-master",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"vimeo/psalm": "^4.22",
"yiisoft/yii-debug-api": "3.0.x-dev",
"yiisoft/yii-debug-viewer": "^3.0@dev"
},
Expand Down
32 changes: 16 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true">
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true">

<php>
<ini name="error_reporting" value="-1"/>
</php>

<coverage>
<include>
<directory>./src</directory>
</include>
<exclude>
<directory>./vendor</directory>
</exclude>
</coverage>

<testsuites>
<testsuite name="Yii _____ tests">
<testsuite name="Yii App">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
15 changes: 7 additions & 8 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

use Yiisoft\Yii\Runner\Http\HttpApplicationRunner;

if (getenv('YII_ENV') === 'test') {
$c3 = dirname(__DIR__) . '/c3.php';
if (file_exists($c3)) {
require_once $c3;
}
}

/**
* @psalm-var string $_SERVER['REQUEST_URI']
*/

// PHP built-in server routing.
if (PHP_SAPI === 'cli-server') {
// Serve static files as is.
Expand All @@ -23,13 +29,6 @@

require_once dirname(__DIR__) . '/autoload.php';

if (getenv('YII_ENV') === 'test') {
$c3 = dirname(__DIR__) . '/c3.php';
if (file_exists($c3)) {
require_once $c3;
}
}

// Run HTTP application runner
$runner = new HttpApplicationRunner(dirname(__DIR__), $_ENV['YII_DEBUG'], $_ENV['YII_ENV']);
$runner->run();
4 changes: 1 addition & 3 deletions resources/views/site/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
</p>

<p>
<a href="<?= $urlGenerator->generate('home') ?>">
Go Back Home
</a>
<a href="<?= $urlGenerator->generate('home') ?>">Go Back Home</a>
</p>
</div>
6 changes: 2 additions & 4 deletions src/Controller/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
use Psr\Http\Message\ResponseInterface;
use Yiisoft\Yii\View\ViewRenderer;

class SiteController
final class SiteController
{
private ViewRenderer $viewRenderer;

public function __construct(ViewRenderer $viewRenderer)
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withControllerName('site');
}
Expand Down
12 changes: 3 additions & 9 deletions src/Handler/NotFoundHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@

final class NotFoundHandler implements RequestHandlerInterface
{
private UrlGeneratorInterface $urlGenerator;
private CurrentRoute $currentRoute;
private ViewRenderer $viewRenderer;

public function __construct(
UrlGeneratorInterface $urlGenerator,
CurrentRoute $currentRoute,
ViewRenderer $viewRenderer
private UrlGeneratorInterface $urlGenerator,
private CurrentRoute $currentRoute,
private ViewRenderer $viewRenderer
) {
$this->urlGenerator = $urlGenerator;
$this->currentRoute = $currentRoute;
$this->viewRenderer = $viewRenderer->withControllerName('site');
}

Expand Down
6 changes: 2 additions & 4 deletions tests/Acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

suite_namespace: App\Tests\Acceptance
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: https://127.0.0.1:8080
- \App\Tests\Helper\Acceptance
step_decorators: ~
url: https://localhost:8080
step_decorators: ~
24 changes: 0 additions & 24 deletions tests/Acceptance/ErrorCest.php

This file was deleted.

18 changes: 18 additions & 0 deletions tests/Acceptance/HomeCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Tests\Acceptance;

use App\Tests\Support\AcceptanceTester;

final class HomeCest
{
public function testIndexPage(AcceptanceTester $I): void
{
$I->wantTo('home page works.');
$I->amOnPage('/');
$I->expectTo('see page home.');
$I->see('Hello!');
}
}
22 changes: 0 additions & 22 deletions tests/Acceptance/IndexCest.php

This file was deleted.

33 changes: 33 additions & 0 deletions tests/Acceptance/NotFoundHandlerCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Tests\Acceptance;

use App\Tests\Support\AcceptanceTester;

final class NotFoundHandlerCest
{
public function about(AcceptanceTester $I): void
{
$I->amOnPage('/about');
$I->wantTo('see about page.');
$I->see('404');
$I->see('The page /about not found.');
$I->see('The above error occurred while the Web server was processing your request.');
$I->see('Please contact us if you think this is a server error. Thank you.');
}

public function aboutReturnHome(AcceptanceTester $I): void
{
$I->amOnPage('/about');
$I->wantTo('see about page.');
$I->see('404');
$I->see('The page /about not found.');
$I->see('The above error occurred while the Web server was processing your request.');
$I->see('Please contact us if you think this is a server error. Thank you.');
$I->click('Go Back Home');
$I->expectTo('see page home.');
$I->see('Hello!');
}
}
7 changes: 3 additions & 4 deletions tests/Cli.suite.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
actor: CliTester
suite_namespace: App\Tests\Cli
modules:
enabled:
- Cli
- \App\Tests\Helper\Cli
step_decorators: ~
# enable helpers as array
enabled: [Cli]
2 changes: 1 addition & 1 deletion tests/Cli/ConsoleCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Tests\Cli;

use App\Tests\CliTester;
use App\Tests\Support\CliTester;

final class ConsoleCest
{
Expand Down
7 changes: 1 addition & 6 deletions tests/Functional.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
#
# Suite for functional tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5, Phalcon4) to use it
# Include one of framework modules (Symfony, Yii2, Laravel, Phalcon4) to use it
# Remove this suite if you don't use frameworks

suite_namespace: App\Tests\Functional
actor: FunctionalTester
modules:
enabled:
- PhpBrowser:
url: https://127.0.0.1:8080
# add a framework module here
- \App\Tests\Helper\Functional
step_decorators: ~
22 changes: 0 additions & 22 deletions tests/Functional/IndexFunctionalCest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests;
namespace App\Tests\Support;

/**
* Inherited Methods
Expand All @@ -16,7 +16,7 @@
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/_support/CliTester.php → tests/Support/CliTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests;
namespace App\Tests\Support;

/**
* Inherited Methods
Expand All @@ -16,7 +16,7 @@
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
Expand Down
Empty file added tests/Support/Data/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests;
namespace App\Tests\Support;

/**
* Inherited Methods
Expand All @@ -16,7 +16,7 @@
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
Expand Down
Loading

0 comments on commit e3a93ee

Please sign in to comment.