Skip to content

Commit

Permalink
Added ability to not exit from PHPUnit test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Apr 7, 2017
1 parent 1c136f6 commit 4591787
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ before_script:

script:
- vendor/bin/phpcs --standard=PSR2 --report=emacs --extensions=php --warning-severity=0 Library/ unit-tests/Extension/ unit-tests/Zephir/
- valgrind --read-var-info=yes --error-exitcode=1 --fullpath-after= --track-origins=yes --leak-check=full ./vendor/bin/phpunit -c phpunit.xml.dist --debug unit-tests/
- valgrind --read-var-info=yes --error-exitcode=1 --fullpath-after= --track-origins=yes --leak-check=full ./unit-tests/phpunit --not-exit -c phpunit.xml.dist --debug unit-tests/

after_failure:
- ./unit-tests/ci/after_failure.sh
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ build_script:

test_script:
- cd %APPVEYOR_BUILD_FOLDER%
- 'vendor/bin/phpunit -c phpunit.xml.dist --debug'
- 'php unit-tests/phpunit -c phpunit.xml.dist --not-exit --debug'

on_failure:
- 'dir'
Expand Down
28 changes: 21 additions & 7 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,29 @@
+--------------------------------------------------------------------------+
*/

error_reporting(E_ALL);
error_reporting(-1);

define('ZEPHIRPATH', __DIR__ . DIRECTORY_SEPARATOR);
define('T', "\t");
define('2T', "\t\t");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
setlocale(LC_ALL, 'en_US.utf-8');

set_time_limit(-1);

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

clearstatcache();

defined('ZEPHIRPATH') || define('ZEPHIRPATH', __DIR__ . DIRECTORY_SEPARATOR);

defined('T') || define('T', "\t");
defined('2T') || define('2T', "\t\t");

if (file_exists(ZEPHIRPATH . 'vendor/autoload.php')) {
require ZEPHIRPATH . 'vendor/autoload.php';
} else {
require __DIR__ . '/Library/Loader.php';
require ZEPHIRPATH . 'Library/Loader.php';
Zephir\Loader::register();
}
3 changes: 2 additions & 1 deletion compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
+--------------------------------------------------------------------------+
*/

require __DIR__ . '/bootstrap.php';
require __DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php';

Zephir\Bootstrap::boot();
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./unit-tests/Bootstrap.php"
bootstrap="./unit-tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand Down
5 changes: 5 additions & 0 deletions unit-tests/Data/TestExClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class TestExClass
{
}
5 changes: 5 additions & 0 deletions unit-tests/Data/TestExInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

interface TestExInterface
{
}
10 changes: 8 additions & 2 deletions unit-tests/Extension/ExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@

namespace Extension;

use Test\Exists;

require DATA_PATH . '/TestExClass.php';
require DATA_PATH . '/TestExInterface.php';

class ExistsTest extends \PHPUnit_Framework_TestCase
{
public function testAssertations()
{
$t = new \Test\Exists();
$t = new Exists();

$this->assertTrue($t->testClassExists('TestExClass'));
$this->assertFalse($t->testClassExists('TestExClassx'));
$this->assertFalse($t->testClassExists('TestExInterface'));
// with namespace
$this->assertTrue($t->testClassExists('\\Test\\Exists'));

$this->assertFalse($t->testInterfaceExists('TestExClass')); // class not interface
// class not interface
$this->assertFalse($t->testInterfaceExists('TestExClass'));
$this->assertTrue($t->testInterfaceExists('TestExInterface'));
$this->assertFalse($t->testInterfaceExists('TestExInterfacex'));

Expand Down
20 changes: 10 additions & 10 deletions unit-tests/Bootstrap.php → unit-tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

require __DIR__ . '/../bootstrap.php';

class TestExClass
{
if (extension_loaded('xdebug')) {
ini_set('xdebug.cli_color', 1);
ini_set('xdebug.collect_params', 0);
ini_set('xdebug.dump_globals', 'on');
ini_set('xdebug.show_local_vars', 'on');
ini_set('xdebug.max_nesting_level', 100);
ini_set('xdebug.var_display_max_depth', 4);
}

interface TestExInterface
{
}

function TestExFunction()
{
}
define('TESTS_PATH', dirname(__FILE__));
define('DATA_PATH', dirname(__FILE__) . '/Data');

if (!extension_loaded('phalcon')) {
include_once __DIR__ . '/../prototypes/phalcon.php';
include_once ZEPHIRPATH . 'prototypes/phalcon.php';
}
39 changes: 39 additions & 0 deletions unit-tests/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013-2017 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| license@zephir-lang.com so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'bootstrap.php';

$exit = true;
if ($index = array_search('--not-exit', $_SERVER['argv'])) {
$exit = false;
unset($_SERVER['argv'][$index]);
}

if (!class_exists('PHPUnit_TextUI_Command')) {
fwrite(STDERR,
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
' composer install' . PHP_EOL . PHP_EOL .
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
);

die(1);
}

PHPUnit_TextUI_Command::main($exit);

0 comments on commit 4591787

Please sign in to comment.