Skip to content

Commit

Permalink
Amended tests (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Nov 17, 2018
1 parent 373e687 commit 8e45876
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
<ini name="display_errors" value="on"/>
<ini name="display_startup_errors" value="on"/>
</php>

<!-- logging>
<log type="coverage-clover" target="./unit-tests/output/clover.xml"/>
<log type="coverage-html" target="./unit-tests/output"/>
</logging -->
</phpunit>
121 changes: 121 additions & 0 deletions unit-tests/Zephir/Test/Command/CompileCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Zephir Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zephir\Test\Command;

use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Output\OutputInterface;
use Zephir\Application;
use Zephir\Command\CompileCommand;
use Zephir\Di\Singleton;
use Zephir\Support\TestCase;
use function Zephir\unlink_recursive;

/**
* Zephir\Test\Command\CompileCommandTest
*
* @package Zephir\Test\CompilerFile
*/
class CompileCommandTest extends TestCase
{
/**
* Common directory.
* unit-tests/Zephir/Test/Command/CompileCommandTest.php
* @var string
*/
private $pwd;

/**
* Store the current directory before to be change.
*
* @return void
*/
public function setUp()
{
$this->pwd = getcwd();
Singleton::reset();
}

/**
* Restore current directory, and clean config.json.
*
* @return void
*/
public function tearDown()
{
if (getcwd() !== $this->pwd) {
if (file_exists('.temp')) {
unlink_recursive('.temp/');
}

if (file_exists('ext')) {
unlink_recursive('ext/');
}

if (file_exists('compile.log')) {
unlink('compile.log');
}

if (file_exists('compile-errors.log')) {
unlink('compile-errors.log');
}

chdir($this->pwd);
}
}

/**
* @test
* @dataProvider devModeProvider
* @issue https://github.com/phalcon/zephir/issues/1520
*
* @param array $mode
* @param string $cflags
*/
public function shouldDetermineDevOption(array $mode, $cflags)
{
// TODO: Create a test for Windows
if (\strtoupper(\substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestSkipped(
'This test currently works on Linux systems only'
);
}

chdir(ZEPHIRPATH . '/unit-tests/fixtures/devmode');

$application = new Application(ZEPHIRPATH);
$application->add(new CompileCommand());

Singleton::getDefault()->get('config')->set('silent', true);

$command = $application->find('compile');
$commandTester = new CommandTester($command);

ob_start();

$commandTester->execute(
['command' => $command->getName()] + $mode,
['verbosity' => OutputInterface::VERBOSITY_QUIET]
);

ob_get_clean();

$this->assertRegexp("/CFLAGS='{$cflags}'/", file_get_contents('ext/config.nice'));
}

public function devModeProvider()
{
return [
[['--no-dev' => true], '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1'],
[['--dev' => true], '-O0 -g3'],
];
}
}
50 changes: 50 additions & 0 deletions unit-tests/fixtures/devmode/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"stubs": {
"stubs-run-after-generate": false
},
"warnings": {
"unused-variable": true,
"unused-variable-external": false,
"possible-wrong-parameter": true,
"possible-wrong-parameter-undefined": false,
"nonexistent-function": true,
"nonexistent-class": true,
"non-valid-isset": true,
"non-array-update": true,
"non-valid-objectupdate": true,
"non-valid-fetch": true,
"invalid-array-index": true,
"non-array-append": true,
"invalid-return-type": true,
"unreachable-code": true,
"nonexistent-constant": true,
"not-supported-magic-constant": true,
"non-valid-decrement": true,
"non-valid-increment": true,
"non-valid-clone": true,
"non-valid-new": true,
"non-array-access": true,
"invalid-reference": true,
"invalid-typeof-comparison": true,
"conditional-initialization": true
},
"optimizations": {
"static-type-inference": true,
"static-type-inference-second-pass": true,
"local-context-pass": true,
"constant-folding": true,
"static-constant-class-folding": true,
"call-gatherer-pass": true,
"check-invalid-reads": false,
"internal-call-transformation": false
},
"namespace": "devmode",
"name": "devmode",
"description": "",
"author": "",
"version": "0.0.1",
"verbose": false,
"requires": {
"extensions": []
}
}
5 changes: 5 additions & 0 deletions unit-tests/fixtures/devmode/devmode/test.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Devmode;

class Test
{
}

0 comments on commit 8e45876

Please sign in to comment.