diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b2a738c28f..091271510f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,4 +29,9 @@ + + diff --git a/unit-tests/Zephir/Test/Command/CompileCommandTest.php b/unit-tests/Zephir/Test/Command/CompileCommandTest.php new file mode 100644 index 0000000000..b4592db7a9 --- /dev/null +++ b/unit-tests/Zephir/Test/Command/CompileCommandTest.php @@ -0,0 +1,121 @@ + + * + * 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'], + ]; + } +} diff --git a/unit-tests/fixtures/devmode/config.json b/unit-tests/fixtures/devmode/config.json new file mode 100644 index 0000000000..dead573a6d --- /dev/null +++ b/unit-tests/fixtures/devmode/config.json @@ -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": [] + } +} diff --git a/unit-tests/fixtures/devmode/devmode/test.zep b/unit-tests/fixtures/devmode/devmode/test.zep new file mode 100644 index 0000000000..dbd57f7459 --- /dev/null +++ b/unit-tests/fixtures/devmode/devmode/test.zep @@ -0,0 +1,5 @@ +namespace Devmode; + +class Test +{ +}