Code Monkey home page Code Monkey logo

c3's Introduction

Stand With Ukraine

Codeception

Latest Stable Total Downloads StandWithUkraine Build status

Modern PHP Testing for everyone

Codeception is a modern full-stack testing framework for PHP. Inspired by BDD, it provides an absolutely new way of writing acceptance, functional and even unit tests.

Contributions

At Codeception we are glad to receive contributions from the community. If you want to send additions or fixes to the code or the documentation please check the Contributing guide.

At a Glance

Describe what you test and how you test it. Use PHP to write descriptions faster.

Run tests and see what actions were taken and what results were seen.

Sample test

$I->amOnPage('/');
$I->click('Pages');
$I->click('New');
$I->see('New Page');
$I->submitForm('form#new_page', ['title' => 'Movie Review']);
$I->see('page created'); // notice generated
$I->see('Movie Review','h1'); // head of page of is our title
$I->seeInCurrentUrl('pages/movie-review'); // slug is generated
$I->seeInDatabase('pages', ['title' => 'Movie Review']); // data is stored in database

For unit testing you can stay on classic PHPUnit tests, as Codeception can run them too.

Installation

Composer

php composer.phar require "codeception/codeception"

TODO: Document how to install the modules, e.g.

php composer.phar require "codeception/module-phpbrowser"

Phar

Download codecept.phar

Copy it into your project.

You can also make Codeception an executable and it put it into your $PATH, for instance:

wget https://codeception.com/codecept.phar

chmod +x codecept.phar

sudo mv codecept.phar /usr/local/bin/codecept

You can then run Codecept in the command line using: codecept bootstrap, codecept run, etc

Run CLI utility:

php codecept.phar

See also Installation | QuickStart

Getting Started

After you successfully installed Codeception, run this command:

codecept bootstrap

This will create a default directory structure and default test suites.

Documentation

View Documentation

The documentation source files can be found at https://github.com/Codeception/codeception.github.com/tree/master/docs/.

License

MIT

c3's People

Contributors

arhell avatar coraxster avatar davertmik avatar dolmen avatar edgardmessias avatar gammamatrix avatar gimler avatar hason avatar jasny avatar jlindenbaum avatar ksiv avatar maksimovic avatar marcelbolten avatar naktibalda avatar olemartinorg avatar ragazzo avatar raistlin avatar rhertogh avatar rowdyelectron avatar samdark avatar sapzape avatar sharky98 avatar slamdunk avatar tiger-seo avatar tobiasstadler avatar vitalyzhakov avatar zk-kb4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c3's Issues

pcov and xdebug errors

Hi!

I have php ZTS 8.2.3, codeception 5.something, c3 lts, one win10 instance and one debian lts 11 ig - ci server with jenkins lts. I have a yii2 project with these.

As for drivers I have pcov lts on the ci and xdebug on win10.

uhm. extra info:
I can't get pcov on win 10, cuz since php 7.4, microsoft doesn't really support the platform anymore, so the old sdk php builder script is not working anymore, and I couldn't figure out since how to compile it locally - pecl is dead as well, so I only got pre-built xdebug.

uhm. I didn't try xdebug on the ci server yet.

So I have a few - mb 100 - unit tests and around 500 functional tests, which are basically e2e tests. I think it shouldn't matter, but I execute the functional tests with the --shard option, which has a small modification in the project that makes the tests to use different db and mailcatcher ports.

ok, that's about it about the environment.

Now, about the issues:

on the win10 local env xdebug works fine with the unit tests and generates nice reports. When I execute the functional tests however, then I gen an error message as a response for each API calls, that looks like this:

[Response] <br />
<b>Fatal error</b>:  Cannot declare class yii\BaseYii, because the name is already in use in <b>C:\xampp\htdocs\portal\api\vendor\yiisoft\yii2\BaseYii.php</b> on line <b>60</
b><br />
<br />
<b>Deprecated</b>:  Creation of dynamic property SebastianBergmann\CodeCoverage\Filter::$whitelistedFiles is deprecated in <b>C:\xampp\htdocs\portal\api\c3.php</b> on line <b
>240</b><br />
<br />
<b>Deprecated</b>:  Creation of dynamic property SebastianBergmann\CodeCoverage\Filter::$isFileCallsCache is deprecated in <b>C:\xampp\htdocs\portal\api\c3.php</b> on line <b
>240</b><br />
<br />
<b>Fatal error</b>:  Uncaught TypeError: Cannot assign __PHP_Incomplete_Class to property SebastianBergmann\CodeCoverage\CodeCoverage::$driver of type SebastianBergmann\CodeC
overage\Driver\Driver in C:\xampp\htdocs\portal\api\c3.php:240
Stack trace:
#0 C:\xampp\htdocs\portal\api\c3.php(240): unserialize('O:43:&quot;Sebastian...')
#1 C:\xampp\htdocs\portal\api\c3.php(410): __c3_factory('C:\\xampp\\htdocs...', true)
#2 [internal function]: {closure}()
#3 {main}
  thrown in <b>C:\xampp\htdocs\portal\api\c3.php</b> on line <b>240</b><br />

This error message only appears when I use the --coverage-html option. Mb it appears with other coverage options as well, I didn't try, but what I tried is that when I don't use any coverage options both the regular test execution and the sharded test execution works fine.

during test execution, in the functional.suite.yml, I use PhpBrowser, and REST module - which depends on PhpBrowser - and the urls are set to /index-test.php
The index-test.php stars like this:

...

if (file_exists(__DIR__ . '/coverage.php')) {
    require __DIR__ . '/coverage.php';
}
... here are the other autoloaders ect.

coverage.php:


if (file_exists(__DIR__ . '/../../c3.php')) {
    require_once __DIR__ . '/../../c3.php';
    define('MY_APP_STARTED', true);
}

ok, so that was the issue with the win10 environment.

CI environment issue that uses pcov:

unit tests are executed fine here as well, results look fancy and all.

functional tests has an issue here as well. If the tests are executed with the non shareded regular method, the execution hangs forever at the 4th tests or so - couldn't figure out yet why, most likely cuz of the background process, that can do something like that if the task that is being processed fails and cant catch the exception.
The other - the one I'm more interested in - is if the tests are executed with the shard option on the first half of the tests, then I get the following message:

In LocalServer.php line 210:

  [yii\base\ErrorException (2)]
  file_get_contents(http://api.takenote.ln/index-test.php/c3/report/html): Fa
  iled to open stream: HTTP request failed! HTTP/1.1 404 Not Found

All the tests pass, but I don't get the coverage summary at the end like I did with the unit tests, I get this error after all the passed tests instead.
When I add the -d option, then I can also see cookie Jar codeception_codeceoverage options passing left and right, so I think something is working.

Things that could help on me:

  • info on whats going on with any of the issues I mentioned
  • php 8.2 compilation guide, so I see what's the new trick that is used to build it after 7.4 on win, so I can compile the pcov with it and then it's easier to debug - if I get the same error locally than on the server.
  • instructions on what should be fixed/what did I mess up most likely/where should I look around first to solve any of these

ty

file_get_contents(http://.../app_test.php//c3/report/serialized): failed to open stream

Hi,

I've been having coideception working in my jenkins server for some time, but now it stoped working, giving me this:
[ErrorException]
file_get_contents(http://packager-api/app_test.php//c3/report/serialized): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error

In my local machine it works perfectly.

I traced it to this in c3.php:23 :
if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE', $_SERVER)) {
return;
}

it exits here, which means HTTP_X_CODECEPTION_CODECOVERAGE is not being set, and it should be set somewhere. In my local machine it sets the test file name.

Can you give me a hint of what's wrong?

Tkx

codeception/codeception/autoload.php not included

What are you trying to achieve?

Create code coverage for acceptance tests.

I'm using Symfony 4.1 and c3.php is included in public/index.php

What do you get instead?

PS C:\Apps\Apache\LPNEW> codecept run acceptance --coverage -vvv

==== Redirecting to Composer-installed version in vendor/codeception ====
Codeception PHP Testing Framework v2.5.0
Powered by PHPUnit 7.3.5 by Sebastian Bergmann and contributors.
Running with seed:


App\Tests.acceptance Tests (2) -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Modules: WebDriver, \App\Tests\Helper\Acceptance
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In ErrorHandler.php line 83:

  [PHPUnit\Framework\Exception (2)]
  file_get_contents(http://127.0.0.1:2779/c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error


Exception trace:
 Codeception\Subscriber\ErrorHandler->errorHandler() at n/a:n/a
 file_get_contents() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Coverage\Subscriber\LocalServer.php:133
 Codeception\Coverage\Subscriber\LocalServer->c3Request() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Coverage\Subscriber\LocalServer.php:72
 Codeception\Coverage\Subscriber\LocalServer->beforeSuite() at C:\Apps\Apache\LPNEW\vendor\symfony\event-dispatcher\EventDispatcher.php:212
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at C:\Apps\Apache\LPNEW\vendor\symfony\event-dispatcher\EventDispatcher.php:44
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\SuiteManager.php:156
 Codeception\SuiteManager->run() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Codecept.php:191
 Codeception\Codecept->runSuite() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Codecept.php:158
 Codeception\Codecept->run() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Command\Run.php:492
 Codeception\Command\Run->runSuites() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Command\Run.php:387
 Codeception\Command\Run->execute() at C:\Apps\Apache\LPNEW\vendor\symfony\console\Command\Command.php:255
 Symfony\Component\Console\Command\Command->run() at C:\Apps\Apache\LPNEW\vendor\symfony\console\Application.php:886
 Symfony\Component\Console\Application->doRunCommand() at C:\Apps\Apache\LPNEW\vendor\symfony\console\Application.php:262
 Symfony\Component\Console\Application->doRun() at C:\Apps\Apache\LPNEW\vendor\symfony\console\Application.php:145
 Symfony\Component\Console\Application->run() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\src\Codeception\Application.php:108
 Codeception\Application->run() at C:\Apps\Apache\LPNEW\vendor\codeception\codeception\package\bin:38
 require() at C:\Users\m.cerovic\AppData\Roaming\Composer\vendor\codeception\codeception\autoload.php:12
 require_once() at C:\Users\m.cerovic\AppData\Roaming\Composer\vendor\codeception\codeception\codecept:7

Details

  • Codeception version: 2.5.0
  • PHP Version: 7.2.8
  • Operating System: WIN10
  • Installation type: Composer
  • Suite configuration:

codeception.yml:

namespace: App\Tests
paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed
coverage:
    enabled: true
    remote: true
    include:
        - src/*
    exclude:
        - src/Kernel.php
params:
    - .env

acceptance.suite.yml:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: 'http://127.0.0.1:2779'
            browser: chrome
            window_size: 976x636
        - \App\Tests\Helper\Acceptance
extensions:
    enabled:
        - Codeception\Extension\Recorder:
            delete_successful: true

Minor improvements to pass psecio-parse's scan

To run report:

composer global require psecio/parse
~/.composer/vendor/bin/psecio-parse scan c3.php

And its results:

  1. /var/www/html/tests/c3.php on line 45
    'header()' calls should not use concatenation directly
header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500);

For more information execute 'psecio-parse rules SetHeaderWithInput'

  1. /var/www/html/tests/c3.php on line 69
    Avoid using AND, OR and XOR (in favor of || and &&) as they may cause subtle precedence bugs
if (!class_exists('PHP_CodeCoverage') and class_exists('SebastianBergmann\CodeCoverage\CodeCoverage')) {

For more information execute 'psecio-parse rules LogicalOperators'

  1. /var/www/html/tests/c3.php on line 137
    The third parameter should be set (and be true) on in_array to avoid type switching issues
if (in_array('GZ', Phar::getSupportedCompression())) {

For more information execute 'psecio-parse rules TypeSafeInArray'

  1. /var/www/html/tests/c3.php on line 184
    The third parameter should be set (and be true) on in_array to avoid type switching issues
if (in_array('GZ', Phar::getSupportedCompression())) {

For more information execute 'psecio-parse rules TypeSafeInArray'

  1. /var/www/html/tests/c3.php on line 204
    The readfile/readlink/readgzfile functions output content directly (possible injection)
readfile($filename);

For more information execute 'psecio-parse rules Readfile'

Code coverage - file_get_contents exception (c3/report/clear)

I'm using Codeception with Laravel 4. In particular I'm trying to use remote code coverage so that I can include acceptance testing in the code coverage results.

XDebug with remote_enable are configured, and c3.php is installed and included in 'public/index.php'.

On Windows everything works as expected. But on Ubuntu 12.04 LTS (with PHP5.4) I get this exception:

 [ErrorException] file_get_contents(http://localhost/c3/report/clear): 
 failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

What am I doing wrong?

Don't work with suite configuration

I try run coverage count by command:

php vendor/bin/codecept run -c api --debug --coverage

And nothing work. I see in Response error: Notice: Undefined variable: settings in /var/www/html/c3.php on line 249 If I parse Exception on 241 line I see message: "Suite api was not loaded" because self::suites is empty in vendor/codeception/base/src/Codeception/Configuration.php:307.

When s3.php run \Codeception\Configuration::suiteSettings($suite, \Codeception\Configuration::config()) without configuration file we see that config method return self::$config and don't run self::loadSuites(); below. It is cause why I see that my suit was not loaded.

My composer versions:,
"codeception/base": "^2.2.3",
"codeception/verify": "~0.3.1",
"phpunit/phpunit": "5.7.27",
"codeception/c3": "2.*"

My project structure
-root
---api
----tests
------api/
------functional/
------unit/
------api.suite.yml
------functional.suite.yml
------unit.suite.yml
----codeception.yml
--backend/
--common/
-codeception.yml

Add composer.json file

It would be nice to be able to install this as a project dependency, even if it's just one file, rather than having to require the file be manually downloaded and placed within the project directory structure or maintained as part of the project repo.

Probleme with pcov

C3 doesn't seem to work with pcov, while everything works fine with xdebug.

Same php code, just the choice of pcov or xdebug in php.ini

Pcov and Xdebug works well for unit tests,

Code Coverage HTML report exhausting all available memory

Hi!

When i'm trying to set up and use code coverage in my codeception tests, i sometimes get this error message:

[UnexpectedValueException]
phar error: "/tmp/C3VVS4ea.tar" is a corrupted tar file (checksum mismatch of file "
Fatal error: Allowed memory size of 402653184 bytes exhausted (tried to allocate 16384 bytes) in /v")

And the content of /tmp/C3VVS4ea.tar includes a full stack trace:

Fatal error: Allowed memory size of 402653184 bytes exhausted (tried to allocate 16384 bytes) in /var/www/vendor/phpunit/php-token-stream/PHP/Token/Stream.php on line 218

Call Stack:
    0.0065     633440   1. {main}() /var/www/c3.php:0
    2.7317  114615016   2. __c3_build_html_report() /var/www/c3.php:209
    2.8414  114681360   3. PHP_CodeCoverage_Report_HTML->process() /var/www/c3.php:43
    2.8473  114681576   4. PHP_CodeCoverage->getReport() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/HTML.php:120
    2.8632  114744664   5. PHP_CodeCoverage_Report_Factory->create() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage.php:158
    3.1713  121803584   6. PHP_CodeCoverage_Report_Factory->addItems() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:75
    3.1714  121808952   7. PHP_CodeCoverage_Report_Factory->addItems() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:97
    3.1714  121814192   8. PHP_CodeCoverage_Report_Factory->addItems() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:97
    3.1715  121819432   9. PHP_CodeCoverage_Report_Factory->addItems() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:97
   17.8675  342026336  10. PHP_CodeCoverage_Report_Factory->addItems() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:97
   21.9244  395074008  11. PHP_CodeCoverage_Report_Node_Directory->addFile() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Factory.php:93
   21.9244  395077600  12. PHP_CodeCoverage_Report_Node_File->__construct() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Node/Directory.php:210
   22.5187  399288184  13. PHP_CodeCoverage_Report_Node_File->calculateStatistics() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Node/File.php:171
   22.5187  399290080  14. PHP_Token_Stream->__construct() /var/www/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/Node/File.php:413
   22.5188  399316352  15. PHP_Token_Stream->scan() /var/www/vendor/phpunit/php-token-stream/PHP/Token/Stream.php:152

I'm not the expert, it seems the code coverage html reports are stored fully in memory at all times, and with big reports it may end up crashing.

Could not write error to log file

While debugging for this issue Codeception/Codeception#4871, I keep getting message Could not write error to log file.
When I traced the cause, it's from here.

c3/c3.php

Lines 36 to 43 in c7348bb

$errorLogFile = defined('C3_CODECOVERAGE_ERROR_LOG_FILE') ?
C3_CODECOVERAGE_ERROR_LOG_FILE :
C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt';
if (is_writable($errorLogFile)) {
file_put_contents($errorLogFile, $message);
} else {
$message = "Could not write error to log file ($errorLogFile), original message: $message";
}

Apparently the c3tmp directory is always emptied by __c3_clear() when the test is executed.

c3/c3.php

Lines 288 to 291 in c7348bb

if ($route === 'clear') {
__c3_clear();
return __c3_exit();
}

This cause problem because is_writable returns true if the file exists and is writable.

http://php.net/manual/en/function.is-writable.php

Read/Write collision when requesting a report

Hi,

There can be instances that might result in incorrect code coverage results due to "truncation".
Local and remote acceptance tests are affected.

The test requests are arriving consecutively on the server and the server starts to process them. Depending on the extend of the tests they might not end in the same order they arrive. So far this is no problem because PR #25 addressed already the read/write collisions.

If a report is requested, either via a route (e.g c3/report/html) or right away from codeception, there is no guarantee that all coverage results are already merged. As a consequence, there can be requests in queue waiting to get access to the locked file to write merged test results along with a read request to create a report. As the order of file access is not guarantee to be the same as the order of incoming server requests, there can be instances where a report is created that lacks some test results due to the fact that they are not merged yet.

A quick and dirty fix is to add a sleep(x) command in a Helper:

<?php declare(strict_types=1);

namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class MyHelper extends \Codeception\Module
{

    // HOOK: after suite
    // Wait a bit to merge all coverage results before requesting the reports.
    // This will avoid a truncated report.
    public function _afterSuite()
    {
        // time must be adjusted depending on the individual situation
        sleep(5);
    }
}

I came across this issue in eLabFTW

I would like to have a better solution but the fix mentioned above is so far the best I have.
One way to fix this issue is provided in #90.

HTTP_X_CODECEPTION_CODECOVERAGE with strange value breaks c3

For some reason I'm getting

$_SERVER[HTTP_X_CODECEPTION_CODECOVERAGE] => remote-access, remote-access, remote-access

Also, it is only defined when accessing the /c3/* routes. Obviously coverage does not work. Following another comment I fixed it temporarily with a hardcoded $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE'] = 'Acceptance'; but this is clearly a hack. Any ideas why this is happening?

Anomaly crash throws 500 error code for request at different placesin the code, no error message

I spent around a week trying to figure out the issue with this one, so I have to leave some info behind for those that might run into the exact same issue.

So I have around a half thousand functional tests on a project. This project has a module which handles some of the test functions that are using in multiple places, and it sends requests to the API, then checks the results there. I have multiple tests that are using this function, and all of them failed with a 500 error code and no response.
I checked the logs everywhere, but they were all empty, so I started to debug the code, because I thought there might be an issue in it that triggers something related to the coverage generation, which then breaks the code. Interestingly if the tests were executed without the coverage option, then all of them passed without an issue. When I debugged the code I experienced that the code gave up on running in random places. It was most of the time around a specific line, but as I executed the test multiple times sometimes it changed. So I thought there might be a memory issue without error message or maybe a limitation that I reached without an error, but as I increased the memory limit I experienced the same issue and the time limit couldn't be an issue either, because the test failed around 12-16s, which was under the default 30s limit.
Long story short there was a line commented out at the start of the c3.php:
// $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'] = 1;
where I thought mb I can use this as a debug flag to check out the issue in this part of the code. So after uncommenting the code the test suddenly started passing with the coverage option and rn the tests are running on both locally and on the CI server, so far everything that failed seems to be passing.

Fatal error from c3.php file

Stepping through my codeception Actor, my code uses amOnPage() to try and load the login page, then grabResponse() and I get this:

<br />
<b>Fatal error</b>:  Uncaught Error: Call to undefined function Codeception\codecept_is_path_absolute() in /srv/www/vendor/codeception/codeception/src/Codeception/Configuration.php:529
Stack trace:
#0 /srv/www/vendor/codeception/codeception/src/Codeception/Configuration.php(557): Codeception\Configuration::outputDir()
#1 /srv/www/c3.php(122): Codeception\Configuration::logDir()
#2 /srv/www/app-loader.php(46): include('...')
#3 /srv/www/public/index.php(2): require_once('...')
#4 {main}
  thrown in <b>/srv/www/vendor/codeception/codeception/src/Codeception/Configuration.php</b> on line <b>529</b><br />

It's been an issue since we upgraded to XDebug 3 and PHP 8 and only happens if running codeception with code coverage enabled

It appears to be an autoload issue of some kind. Here's my app-loader.php code (up until where it fails)


<?php // phpcs:ignore

use Bugsnag\Client as BugsnagClient;
use Pi\Core\Bootstrap\Autoloader;
use Pi\Core\Bootstrap\ConfigBuilder;
use Pi\Core\Bootstrap\ContainerBootstrap;
use Pi\Core\Bootstrap\EntryPointResolver;
use Pi\Core\Bootstrap\SessionInitialiser;
use Pi\Core\Bootstrap\ZendApplicationBootstrapProxy;
use Pi\Core\ErrorHandling\ErrorHandler;

/**
 * Need to set this here as some of the logic which executes before bootstrap requires a date
 */
date_default_timezone_set('UTC');

/**
 * Base directory of entire application
 */
define('APPLICATION_ROOT', dirname(__FILE__));

/**
 * Location of the "application" directory - required by Zend
 */
define('APPLICATION_PATH', APPLICATION_ROOT . '/application');

/**
 * Defines whether the app was invoked through the web or command line
 */
define('INVOCATION_MODE', PHP_SAPI === 'cli' ? 'cli' : 'http');

require_once APPLICATION_ROOT . '/vendor/autoload.php';
require_once APPLICATION_PATH . '/configs/environment.php';

// We need our own autoloader to handle our non-psr-4 module structure
// It may make sense to load this in composer.json instead
require APPLICATION_PATH . '/modules/core/code/Bootstrap/Autoloader.php';
spl_autoload_register([new Autoloader(), 'autoload']);

$entryPoint = (new EntryPointResolver())->determineEntryPoint();

$config = (new ConfigBuilder())->initConfig($entryPoint);

if ($config->codeception->codecoverage === '1') {
    define('C3_CODECOVERAGE_ERROR_LOG_FILE', APPLICATION_ROOT . '/var/log/c3_error.log');
    include APPLICATION_ROOT . '/c3.php';
    define('MY_APP_STARTED', true);
}

Error on composer update

On last update, 2.0.13, when I try to composer update, got following error:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Codeception\c3\Installer::copyC3(), 0 passed in C:\www\PPA_DDD\vendor\codeception\c3\Installer.php on line 88 and exactly 1 expected in C:\www\PPA_DDD\vendor\codeception\c3\Installer.php:62 Stack trace: #0 C:\www\PPA_DDD\vendor\codeception\c3\Installer.php(88): Codeception\c3\Installer->copyC3() #1 [internal function]: Codeception\c3\Installer->askForUpdate(Object(Composer\Installer\PackageEvent)) #2 phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(171): call_user_func(Array, Object(Composer\Installer\PackageEvent)) #3 phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(116): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Installer\PackageEvent)) #4 phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php(608): Composer\EventDispatcher\EventDispatcher->dispatchPackageEvent('post-package-up...', true, Ob in C:\www\PPA_DDD\vendor\codeception\c3\Installer.php on line 62

There is a missing $event as parameter in line 88 of Installer.php

Composer Plugin API is deprecated

I noticed this warning in failed build

Deprecation warning: require.composer-plugin-api is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "a-z0-9/a-z0-9". Make sure you fix this as Composer 2.0 will error.

New idea for remote CC

After reviewing #85 (good work keep it going!) I thought of a different approach to code coverage that might work cleanly as well.

The idea:

  1. Before a test starts, connect to C3, this is a "long lived" connection. C3 creates a file temp file with a fixed name and watches it for data, this data is streamed back to the coverage module.
  2. During the test each request to the server is profiled and the serialized result (php-codecoverage library supports serialization) is atomically written to the local temp file.
  3. After the test ends we disconnect the stream from 1 and this prompts the remote coverage file to be removed

This could simplify things:

  • We no longer need to mark each request with a cookie, which needs to be set in the browser module (Selenium, REST, or Php)
  • We no longer have edge cases where fetch requests might not send cookies for example
  • We cannot support parallel tests since we won't be able to know to which test the coverage belongs

Streaming coverage

We can stream coverage for each request like this using the PHP report class (copied below since its short)

final class PHP
{
    public function process(CodeCoverage $coverage, ?string $target = null): string
    {
        $coverage->clearCache();

        $buffer = "<?php
return \unserialize(<<<'END_OF_COVERAGE_SERIALIZATION'" . PHP_EOL . serialize($coverage) . PHP_EOL . 'END_OF_COVERAGE_SERIALIZATION' . PHP_EOL . ');';

        if ($target !== null) {
            if (!strpos($target, '://') !== false) {
                Filesystem::createDirectory(dirname($target));
            }

            if (@file_put_contents($target, $buffer) === false) {
                throw new WriteOperationFailedException($target);
            }
        }

        return $buffer;
    }
}
  1. Capture it like normal
  2. Use the SebastianBergmann\CodeCoverage\Report\PHP report to process it to a string
  3. Stream the result to the calling code
  4. The calling code splits it using the end marker.
  5. Each part is deserialized to an of Coverage, which can be merged with the base coverage object via $baseCoverage->append($unserializedCoverage)`

Optionally we could do some automatic path detection which in most cases should actually be trivial.

Thoughts?

Codeception is not loaded

Hi,

I'm getting the next message:

Codeception is not loaded. Please check that either PHAR or Composer or PEAR package can be used

In the c3.php file I see an if, else if, else if, else to get the right location of the codeception. My location is not in that list.(~/bin/vendor/composer) So now you have again a new case.

Maybe create a config file for it? ;)
so the programmer can gives his whole path to the codeception.

C3 v2.6.0 Generates Error

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Codeception\c3\Installer::copyC3V2() must be an instance of Composer\Script\Event, null given, called in /vendor/codeception/c3/Installer.php on line 85 and defined in /vendor/codeception/c3/Installer.php:88

The Installer.php file has been updated to use copyC3V2 which defines copyC3V2(Event $event) but doesn't allow null, line 85 calls copyC3V2 with a null variable.

remote coverage result all 0

codeception.yml like this:
image

api.suit.yml like this:
image

index.php
image

when i test in command:
php vendor/codeception/codeception/codecept run --coverage --coverage-xml --coverage-html

_output/coverage:open the html ,nothing to test result all zero;how can t do to get the right coverage?
image

Composer update still fatal errors.

#34 seems not solved!

  - Updating codeception/c3 (2.0.12 => 2.0.14): Loading from cache
c3.php has changed Do you want to replace c3.php with latest version?yes
PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function Codeception\c3\Installer::copyC3(), 0 passed in /data/shop/development/current/vendor/codeception/c3/Installer.php on line 88 and exactly 1 expected in /data/shop/development/current/vendor/codeception/c3/Installer.php:62

Minimal dependences

So... c3.php don't run without Codeception\Codeception

Add Codeception to composer require-dev is owerkill.

O_O

Can you get minimal requirements for coverage acceptance tests? Unit and Functional tests coverage I will run using docker image of codeception.

Or I must use another way?

Error on composer update

If run composer update, show this error:

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Call to undefined method Composer\DependencyResolver\Operation\InstallOperation::getTargetPackage()

If run composer install, not show error:

c3.php throwing PHP Warnings with Vagrant

Description

I seem to receiving an error when trying to generate code coverage for functional tests inside Vagrant. The tests run and the code coverage generates fine but some test fail (namely any check on the response being valid JSON) due to PHP Warnings being thrown by the c3.php file.

Steps

When ssh'd into vagrant, I run this command:

./vendor/bin/codecept run functional --coverage-html=blah tests/functional/Company/Product/CategoriesCest.php

All 3 tests fail when trying to assert $I->seeResponseIsJson();. When taking a look at the failure report generate in tests/_output/tests.Company.Product.CategoriesCest.orderCategoriesDesc.fail.html I see the following error:

Warning: file_put_contents(/var/www/phpapps/api.testurl.test/tests/_output/c3tmp/codecoverage.serialized): failed to open stream: Permission denied in /var/www/phpapps/api.testurl.test/c3.php on line 321

At line 321, c3.php is trying to execute:

c3/c3.php

Lines 320 to 322 in f08f20b

if ($file === null) {
file_put_contents($current_report, serialize($existingCodeCoverage), LOCK_EX);
} else {

which it can't complete because the permissions for c3tmp directory are as follows:

drwxr-xr-x 1 vagrant vagrant     68 Aug 10 08:55 c3tmp/

I'm puzzled as to why codeception wouldn't have permissions to write codecoverage.serialized in c3tmp/ when it has created the directory itself... Furthermore, applying full read-write permissions to the c3tmp/ via:

chmod -R 777 tests/_output/c3tmp/

results in even more PHP Warnings being generated seemingly from the same type of issue i.e incorrect file permissions, read-write lock etc. I've detailed these issues below:

Warning: fopen(/var/www/phpapps/api.testurl.test/tests/_output/c3tmp/codecoverage.serialized): failed to open stream: Permission denied in /var/www/phpapps/api.testurl.test/c3.php on line 184

Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/phpapps/api.testurl.test/c3.php on line 185

Notice: Undefined variable: phpCoverage in /var/www/phpapps/api.testurl.test/c3.php on line 194

Fatal error: Call to a member function merge() on a non-object in /var/www/phpapps/api.testurl.test/c3.php on line 318

Additional Information

  • Vagrant: Vagrant 1.9.2

  • PHP: PHP 5.5.9-1ubuntu4.20 (cli)

  • functional.suite.dist.yml

class_name: FunctionalTester
error_level: -1
coverage:
    enabled: true
modules:
    enabled: [PhpBrowser, REST, Asserts, FunctionalHelper]
    config:
        PhpBrowser:
            url: http://api.testurl.test/
        REST:
            url: http://api.testurl.test/
  • codeception.yml
actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
coverage:
    enabled: true
    whitelist:
        include:
            - src/*
            - public/*
        exclude:
            - src/Company/*/apidoc.json
            - src/Company/*/apiDocVersioning/*

Constant C3_CODECOVERAGE_MEDIATE_STORAGE can be used before it's defined

If these lines fail:

try {
    \Codeception\Configuration::config($config_file);
} catch (\Exception $e) {
    __c3_error($e->getMessage());
}

due to \Codeception\Configuration not existing, then

        $errorLogFile = defined('C3_CODECOVERAGE_ERROR_LOG_FILE') ?
            C3_CODECOVERAGE_ERROR_LOG_FILE :
            C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt';

is called before

    define('C3_CODECOVERAGE_MEDIATE_STORAGE', Codeception\Configuration::logDir() . 'c3tmp');
    define('C3_CODECOVERAGE_PROJECT_ROOT', Codeception\Configuration::projectDir());
    define('C3_CODECOVERAGE_TESTNAME', $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE']);

is run.

Uncaught Error: Undefined constant C3_CODECOVERAGE_MEDIATE_STORAGE

<br />
<b>Fatal error</b>:  Uncaught Error: Undefined constant &quot;C3_CODECOVERAGE_MEDIATE_STORAGE&quot; in /app/vendor/codeception/c3/c3.php:45
Stack trace:
#0 /app/vendor/codeception/c3/c3.php(71): __c3_error('Codeception is ...')
#1 /app/public/index.php(7): require_once('/app/vendor/cod...')
#2 {main}
  thrown in <b>/app/vendor/codeception/c3/c3.php</b> on line <b>45</b><br />

environment:

  • php 8.2
  • symfony 6.2

index.php

<?php

declare(strict_types=1);

use App\Kernel;

require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';
require_once dirname(__DIR__) . '/vendor/codeception/c3/c3.php';


return static fn (array $context): Kernel => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.