public function test_php_versions() { $code = '<?php cyrus_close(null); ?>'; $options = new PC_Engine_Options(); $options->add_project(PC_Project::PHPREF_ID); $options->add_min_req('PHP', '4.0.0'); $options->add_max_req('PHP', '5.1.0'); $options->add_min_req('PECL cyrus', '1.0.0'); list(, , , , $errors) = $this->analyze($code, $options); self::assert_equals(2, count($errors)); $error = $errors[0]; self::assert_equals(PC_Obj_Error::E_S_REQUIRES_NEWER, $error->get_type()); self::assert_equals('cyrus_close(unknown) requires PHP >= 4.1.0, but you target PHP >= 4.0.0', $error->get_msg()); $error = $errors[1]; self::assert_equals(PC_Obj_Error::E_S_REQUIRES_OLDER, $error->get_type()); self::assert_equals('cyrus_close(unknown) exists only till PHP 5, but you target PHP < 5.1.0', $error->get_msg()); }
public function run($args) { $project = FWS_Props::get()->project(); $options = new PC_Engine_Options(); $options->set_report_unused(true); $options->set_report_argret_strictly($project->get_report_argret_strictly()); $options->add_project($project->get_id()); foreach ($project->get_project_deps() as $pid) { $options->add_project($pid); } foreach ($project->get_req() as $r) { if ($r['type'] == 'min') { $options->add_min_req($r['name'], $r['version']); } else { $options->add_max_req($r['name'], $r['version']); } } $env = new PC_Engine_Env($options); $ascanner = new PC_Engine_StmtScannerFrontend($env); $msgs = array(); foreach ($args as $file) { try { $ascanner->scan_file($file); } catch (PC_Engine_Exception $e) { $msgs[] = $e->__toString(); } } if (count($env->get_types()->get_calls())) { PC_DAO::get_calls()->create_bulk($env->get_types()->get_calls()); } foreach ($env->get_errors()->get() as $err) { PC_DAO::get_errors()->create($err); } foreach ($ascanner->get_vars() as $vars) { foreach ($vars as $var) { PC_DAO::get_vars()->create($var); } } // write messages to shared data $mutex = new FWS_MutexFile(PC_CLI_MUTEX_FILE); $mutex->aquire(); $data = unserialize($mutex->read()); /* @var $data PC_JobData */ $data->add_errors($msgs); $mutex->write(serialize($data)); $mutex->close(); }
public function test_varvars() { $code = '<?php class foo { const ABC = 5; public $XYZ = 4; public static function test() { } } class bar {} function foo() {} function bar() {} $a = "foo"; ${$a} = "bar"; ${"bar"} = 2; ${"foo"."bar"} = 3; ${$a + 1} = $a::$XYZ; ${1.2} = $a::ABC; ${$_} = 1; $a(); ${$a}(); $_(); new $a(); new ${$a}(); new $_(); $a::test(); $Bar = "b"; $Foo = "Bar"; $World = "Foo"; $Hello = "World"; $b = "Hello"; $c = $b; $d = $$b; $e = $$$b; $f = $$$$b; $g = $$$$$b; $h = $$$$$$b; $i = $$$$$$$b; ?>'; $options = new PC_Engine_Options(); $options->add_project(PC_Project::PHPREF_ID); $options->add_min_req('PHP', '5'); list(, , $vars, $calls, $errors) = $this->analyze($code, $options); self::assert_equals(0, count($errors)); $global = $vars[PC_Obj_Variable::SCOPE_GLOBAL]; self::assert_equals(18, count($global)); self::assert_equals('string=foo', (string) $global['a']->get_type()); self::assert_equals('string=bar', (string) $global['foo']->get_type()); self::assert_equals('integer=2', (string) $global['bar']->get_type()); self::assert_equals('integer=3', (string) $global['foobar']->get_type()); self::assert_equals('integer=4', (string) $global['1']->get_type()); self::assert_equals('integer=5', (string) $global['1.2']->get_type()); self::assert_equals('string=Hello', (string) $global['b']->get_type()); self::assert_equals('string=Hello', (string) $global['c']->get_type()); self::assert_equals('string=World', (string) $global['d']->get_type()); self::assert_equals('string=Foo', (string) $global['e']->get_type()); self::assert_equals('string=Bar', (string) $global['f']->get_type()); self::assert_equals('string=b', (string) $global['g']->get_type()); self::assert_equals('string=Hello', (string) $global['h']->get_type()); self::assert_equals('string=World', (string) $global['i']->get_type()); self::assert_equals(5, count($calls)); self::assert_equals('foo()', (string) $calls[0]); self::assert_equals('bar()', (string) $calls[1]); self::assert_equals('foo->__construct()', (string) $calls[2]); self::assert_equals('bar->__construct()', (string) $calls[3]); self::assert_equals('foo::test()', (string) $calls[4]); }