Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate uses #68

Merged
merged 10 commits into from
Apr 6, 2015
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ XP Framework Core ChangeLog

### Heads up!

* Deprecated uses() core functionality - use the `use` statement and PHP's
namespaces instead. This also deprecates classes in the global namespace
and the "package"-classes introduced in xp-framework/rfc#37.
(@thekid)
* Deprecated raise() core functionality - use the `throw` statement
instead, it also uses lazy classloading for namespaced classes.
(@thekid)
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function __error($code, $msg, $file, $line) {
}
// }}}

// {{{ proto void uses (string* args)
// {{{ proto deprecated void uses (string* args)
// Uses one or more classes
function uses() {
$scope= null;
Expand Down
3 changes: 0 additions & 3 deletions src/test/config/unittest/core.ini
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ class="net.xp_framework.unittest.reflection.PrivateAccessibilityTest"
[generics.definition]
class="net.xp_framework.unittest.core.generics.DefinitionReflectionTest"

[generics.nsdefinition]
class="net.xp_framework.unittest.core.generics.NSDefinitionReflectionTest"

[generics.instance]
class="net.xp_framework.unittest.core.generics.InstanceReflectionTest"

Expand Down
151 changes: 72 additions & 79 deletions src/test/php/net/xp_framework/unittest/DemoTest.class.php
Original file line number Diff line number Diff line change
@@ -1,94 +1,87 @@
<?php
/* This class is part of the XP framework
<?php namespace net\framework\unittest;

/**
* Shows different test scenarios
*
* $Id$
* @purpose Unit Test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed while at it

*/

uses('unittest.TestCase');
class DemoTest extends \unittest\TestCase {

/**
* Shows different test scenarios
* A test that always succeeds
*
* @purpose Unit Test
*/
class DemoTest extends TestCase {

/**
* A test that always succeeds
*
*/
#[@test]
public function alwaysSucceeds() {
$this->assertTrue(TRUE);
}
#[@test]
public function alwaysSucceeds() {
$this->assertTrue(true);
}

/**
* A test that is ignored
*
*/
#[@test, @ignore('Ignored')]
public function ignored() {
$this->fail('Ignored test executed', 'executed', 'ignored');
}
/**
* A test that is ignored
*
*/
#[@test, @ignore('Ignored')]
public function ignored() {
$this->fail('Ignored test executed', 'executed', 'ignored');
}

/**
* Setup method
*
*/
public function setUp() {
if (0 == strcasecmp('alwaysSkipped', $this->name)) {
throw new PrerequisitesNotMetError('Skipping', null, $this->name);
}
/**
* Setup method
*
*/
public function setUp() {
if ('alwaysSkipped' === $this->name) {
throw new PrerequisitesNotMetError('Skipping', null, $this->name);
}
}

/**
* A test that is skipped due to not met prerequisites.
*
*/
#[@test]
public function alwaysSkipped() {
$this->fail('Skipped test executed', 'executed', 'skipped');
}
/**
* A test that is skipped due to not met prerequisites.
*
*/
#[@test]
public function alwaysSkipped() {
$this->fail('Skipped test executed', 'executed', 'skipped');
}

/**
* A test that always fails because of a failed assertion
*
*/
#[@test]
public function alwaysFails() {
$this->assertTrue(FALSE);
}
/**
* A test that always fails because of a failed assertion
*
*/
#[@test]
public function alwaysFails() {
$this->assertTrue(false);
}

/**
* A test that always fails because the expected exception was not
* thrown.
*
*/
#[@test, @expect('lang.IllegalArgumentException')]
public function expectedExceptionNotThrown() {
TRUE;
}
/**
* A test that always fails because the expected exception was not
* thrown.
*
*/
#[@test, @expect('lang.IllegalArgumentException')]
public function expectedExceptionNotThrown() {
true;
}

/**
* A test that always fails because an exception is thrown.
*
*/
#[@test]
public function throwsAnException() {
throw new IllegalArgumentException('');
}
/**
* A test that always fails because an exception is thrown.
*
*/
#[@test]
public function throwsAnException() {
throw new IllegalArgumentException('');
}

/**
* A test that timeouts
*
*/
#[@test, @limit(time= 0.1)]
public function timeouts() {
$start= gettimeofday();
$end= (1000000 * $start['sec']) + $start['usec'] + 1000 * 200; // 0.2 seconds
do {
$now= gettimeofday();
} while ((1000000 * $now['sec']) + $now['usec'] < $end);
}
/**
* A test that timeouts
*
*/
#[@test, @limit(time= 0.1)]
public function timeouts() {
$start= gettimeofday();
$end= (1000000 * $start['sec']) + $start['usec'] + 1000 * 200; // 0.2 seconds
do {
$now= gettimeofday();
} while ((1000000 * $now['sec']) + $now['usec'] < $end);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this was done because usleep() didn't work reliably on some platforms. Guess this can go by now.

?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public static function verifyProcessExecutionEnabled() {
/**
* Create a new runtime
*
* @param string[] uses
* @param string decl
* @param lang.RuntimeOptions $options
* @return var[] an array with three elements: exitcode, stdout and stderr contents
*/
protected function runWith(\lang\RuntimeOptions $options) {
Expand All @@ -36,7 +35,7 @@ protected function runWith(\lang\RuntimeOptions $options) {
// Close child process
$exitv= $p->close();
}
return array($exitv, $out, $err);
return [$exitv, $out, $err];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ protected function processExecutionEnabled() {
}

/**
* Issues a uses() command inside a new runtime for every class given
* and returns a line indicating success or failure for each of them.
* Runs sourcecode inside a new runtime
*
* @param string[] uses
* @param string src
* @param string $src
* @return var[] an array with three elements: exitcode, stdout and stderr contents
*/
protected function runInNewRuntime($uses, $src) {
protected function runInNewRuntime($src) {
with ($out= $err= '', $p= Runtime::getInstance()->newInstance(null, 'class', 'xp.runtime.Evaluate', [])); {
$uses && $p->in->write('uses("'.implode('", "', $uses).'");');
$p->in->write($src);
$p->in->close();

Expand Down Expand Up @@ -186,7 +183,7 @@ public function arguments_are_passed_to_base_constructor_in_closuremap() {

#[@test, @action([new RuntimeVersion('>=5.6'), new VerifyThat('processExecutionEnabled')])]
public function variadic_argument_passing() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
class Test {
public function verify() {
$r= newinstance("lang.Object", [1, 2, 3], [
Expand All @@ -207,7 +204,7 @@ public function verify() {

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function missingMethodImplementationFatals() {
$r= $this->runInNewRuntime(['lang.Runnable'], '
$r= $this->runInNewRuntime('
newinstance("lang.Runnable", [], "{}");
');
$this->assertEquals(255, $r[0], 'exitcode');
Expand All @@ -219,7 +216,7 @@ public function missingMethodImplementationFatals() {

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function syntaxErrorFatals() {
$r= $this->runInNewRuntime(['lang.Runnable'], '
$r= $this->runInNewRuntime('
newinstance("lang.Runnable", [], "{ @__SYNTAX ERROR__@ }");
');
$this->assertEquals(255, $r[0], 'exitcode');
Expand All @@ -231,7 +228,7 @@ public function syntaxErrorFatals() {

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function missingClassFatals() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
newinstance("lang.NonExistantClass", [], "{}");
');
$this->assertEquals(255, $r[0], 'exitcode');
Expand All @@ -243,7 +240,7 @@ public function missingClassFatals() {

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function notPreviouslyDefinedClassIsLoaded() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
if (isset(xp::$cl["lang.Runnable"])) {
xp::error("Class lang.Runnable may not have been previously loaded");
}
Expand Down Expand Up @@ -377,7 +374,7 @@ public function this_can_be_accessed() {

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function declaration_with_array_typehint() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
abstract class Base extends \lang\Object {
public abstract function fixture(array $args);
}
Expand All @@ -392,7 +389,7 @@ public abstract function fixture(array $args);

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function declaration_with_callable_typehint() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
abstract class Base extends \lang\Object {
public abstract function fixture(callable $args);
}
Expand All @@ -407,7 +404,7 @@ public abstract function fixture(callable $args);

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function declaration_with_class_typehint() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
abstract class Base extends \lang\Object {
public abstract function fixture(\lang\Generic $args);
}
Expand All @@ -422,7 +419,7 @@ public abstract function fixture(\lang\Generic $args);

#[@test, @action(new VerifyThat('processExecutionEnabled'))]
public function declaration_with_self_typehint() {
$r= $this->runInNewRuntime([], '
$r= $this->runInNewRuntime('
abstract class Base extends \lang\Object {
public abstract function fixture(self $args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* TestCase for `uses()` statement
*
* @deprecated Use the `use` statement and namespaces instead
*/
class UsesTest extends \unittest\TestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
<?php
/* This class is part of the XP framework
<?php namespace net\xp_framework\unittest\core\generics;

/**
* Lookup map
*
* $Id$
*/

$package= 'net.xp_framework.unittest.core.generics';

uses('net.xp_framework.unittest.core.generics.IDictionary');

#[@generic(self= 'K, V', implements= array('K, V'))]
abstract class AbstractDictionary extends \lang\Object implements IDictionary {

/**
* Lookup map
* Constructor
*
* @param [:var] initial
*/
#[@generic(self= 'K, V', implements= array('K, V'))]
abstract class net�xp_framework�unittest�core�generics�AbstractDictionary extends Object implements net�xp_framework�unittest�core�generics�IDictionary {

/**
* Constructor
*
* @param array<string, var> initial
*/
public function __construct($initial= []) {
foreach ($initial as $key => $value) {
$this->put($key, $value);
}
public function __construct($initial= []) {
foreach ($initial as $key => $value) {
$this->put($key, $value);
}
}
?>
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
<?php
/* This class is part of the XP framework
<?php namespace net\xp_framework\unittest\core\generics;

/**
* Lookup map
*
* $Id$
*/
#[@generic(self= 'V', implements= array('lang.Type, V'))]
abstract class AbstractTypeDictionary extends \lang\Object implements IDictionary {

$package= 'net.xp_framework.unittest.core.generics';

uses('net.xp_framework.unittest.core.generics.IDictionary');

/**
* Lookup map
*
*/
#[@generic(self= 'V', implements= array('lang.Type, V'))]
abstract class net�xp_framework�unittest�core�generics�AbstractTypeDictionary extends Object implements net�xp_framework�unittest�core�generics�IDictionary {

}
?>
}
Loading