Skip to content

Commit

Permalink
Remove test verifications for no longer supported PHP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 23, 2024
1 parent cd57990 commit 1b7e0d7
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 42 deletions.
23 changes: 5 additions & 18 deletions src/test/php/lang/unittest/ErrorsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
IndexOutOfBoundsException,
NullPointerException,
Value,
XPException
Throwable
};
use test\verify\Runtime;
use test\{Action, Assert, Before, Expect, Test};

class ErrorsTest {
Expand All @@ -32,8 +31,8 @@ public function errors_appear_in_stacktrace() {
trigger_error('Test error');

try {
throw new XPException('');
} catch (XPException $e) {
throw new Throwable('');
} catch (Throwable $e) {
$element= $e->getStackTrace()[0];
Assert::equals(
['file' => __FILE__, 'message' => 'Test error'],
Expand Down Expand Up @@ -102,25 +101,13 @@ public function argument_mismatch_yield_type_exception() {
$f('Primitive');
}

#[Test, Expect(IllegalArgumentException::class), Runtime(php: '<7.1.0-dev')]
public function missing_argument_mismatch_yield_iae() {
$f= function($arg) { };
$f();
}

#[Test, Expect(Error::class), Runtime(php: '>=7.1.0')]
#[Test, Expect(Error::class)]
public function missing_argument_mismatch_yield_error() {
$f= function($arg) { };
$f();
}

#[Test, Expect(ClassCastException::class), Runtime(php: '<7.4.0-dev')]
public function cannot_convert_object_to_string_yields_cce() {
$object= new class() { };
$object.'String';
}

#[Test, Expect(Error::class), Runtime(php: '>=7.4.0')]
#[Test, Expect(Error::class)]
public function cannot_convert_object_to_string_yields_error() {
$object= new class() { };
$object.'String';
Expand Down
7 changes: 3 additions & 4 deletions src/test/php/lang/unittest/FieldTypeTest.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace lang\unittest;

use lang\{ArrayType, MapType, Primitive, Type, Value, XPClass};
use test\verify\Runtime;
use test\{Action, Assert, Test, Values};

class FieldTypeTest extends FieldsTest {
Expand Down Expand Up @@ -61,7 +60,7 @@ public function self_type_via_apidoc() {
Assert::equals($fixture, $fixture->getField('fixture')->getType());
}

#[Test, Runtime(php: '>=7.4')]
#[Test]
public function self_type_via_syntax() {
$fixture= $this->type('{ public self $fixture; }');
Assert::equals('self', $fixture->getField('fixture')->getTypeName());
Expand All @@ -74,7 +73,7 @@ public function array_of_self_type() {
Assert::equals(new ArrayType($fixture), $fixture->getField('fixture')->getType());
}

#[Test, Runtime(php: '>=7.4')]
#[Test]
public function specific_array_type_determined_via_apidoc() {
$fixture= $this->type('{ /** @type string[] */ public array $fixture; }');
Assert::equals('string[]', $fixture->getField('fixture')->getTypeName());
Expand All @@ -86,7 +85,7 @@ public function untyped_restriction() {
Assert::null($this->field('public $fixture;')->getTypeRestriction());
}

#[Test, Runtime(php: '>=7.4')]
#[Test]
public function typed_restriction() {
Assert::equals(Primitive::$STRING, $this->field('public string $fixture;')->getTypeRestriction());
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/php/lang/unittest/MethodInvocationTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use lang\reflect\TargetInvocationException;
use lang\{IllegalAccessException, IllegalArgumentException};
use test\verify\Runtime;
use test\{Action, Assert, Expect, Test, Values};

class MethodInvocationTest extends MethodsTest {
Expand Down Expand Up @@ -43,13 +42,13 @@ public function exceptions_raised_during_invocation_are_wrapped() {
$fixture->getMethod('fixture')->invoke($fixture->newInstance(), []);
}

#[Test, Expect(TargetInvocationException::class), Runtime(php: '>=7.0')]
#[Test, Expect(TargetInvocationException::class)]
public function exceptions_raised_for_return_type_violations() {
$fixture= $this->type('{ public function fixture(): array { return null; } }');
$fixture->getMethod('fixture')->invoke($fixture->newInstance(), []);
}

#[Test, Expect(TargetInvocationException::class), Runtime(php: '>=7.0')]
#[Test, Expect(TargetInvocationException::class)]
public function exceptions_raised_for_parameter_type_violations() {
$fixture= $this->type('{ public function fixture(int $i) { } }');
$fixture->getMethod('fixture')->invoke($fixture->newInstance(), ['abc']);
Expand Down
4 changes: 2 additions & 2 deletions src/test/php/lang/unittest/MethodParametersTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public function parameter_type_determined_via_syntax($literal, $type) {
);
}

#[Test, Runtime(php: '>=7.0'), Values([['string'], ['int'], ['bool'], ['float']])]
#[Test, Values([['string'], ['int'], ['bool'], ['float']])]
public function parameter_type_determined_via_scalar_syntax($literal) {
$this->assertParamType(
Primitive::forName($literal),
$this->method('public function fixture('.$literal.' $param) { }')->getParameter(0)
);
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function nullable_parameter_type() {
$fixture= $this->type('{ public function fixture(?string $arg) { } }');
$this->assertParamType(
Expand Down
6 changes: 3 additions & 3 deletions src/test/php/lang/unittest/MethodReturnTypesTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function return_type_determined_via_syntax($literal, $type) {
$this->assertReturnType($type, $this->method('public function fixture(): '.$literal.' { }'));
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function void_return_type() {
$fixture= $this->type('{ public function fixture(): void { } }');
$this->assertReturnType(Type::$VOID, $fixture->getMethod('fixture'));
Expand All @@ -95,7 +95,7 @@ public function never_return_type() {
$this->assertReturnType(Type::$NEVER, $fixture->getMethod('fixture'));
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function nullable_return_type() {
$fixture= $this->type('{ public function fixture(): ?string { } }');
$this->assertReturnType(new Nullable(Primitive::$STRING), $fixture->getMethod('fixture'));
Expand Down Expand Up @@ -186,7 +186,7 @@ public function apidoc_supersedes_self_type_restriction() {
Assert::equals('static', $method->getReturnTypeName(), 'name');
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function apidoc_supersedes_void_type_restriction() {
$method= $this->type('{ /** @return never */ public function fixture(): void { exit(); } }')->getMethod('fixture');

Expand Down
14 changes: 7 additions & 7 deletions src/test/php/lang/unittest/NewInstanceTest.class.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php namespace lang\unittest;

use ReturnTypesWillChange;
use lang\Runtime as XPRuntime;
use lang\Runtime;
use lang\reflect\Package;
use lang\{ClassFormatException, ClassLoader, IllegalAccessException, Process, Runnable, Value};
use test\verify\{Condition, Runtime};
use test\verify\Condition;
use test\{Assert, Expect, Test, Values};
use util\Objects;

Expand All @@ -22,7 +22,7 @@ protected static function processExecutionEnabled() {
* @return var[] an array with three elements: exitcode, stdout and stderr contents
*/
protected function runInNewRuntime($src) {
return with (XPRuntime::getInstance()->newInstance(null, 'class', 'xp.runtime.Evaluate', []), function($p) use($src) {
return with (Runtime::getInstance()->newInstance(null, 'class', 'xp.runtime.Evaluate', []), function($p) use($src) {
$p->in->write($src);
$p->in->close();

Expand Down Expand Up @@ -491,7 +491,7 @@ public abstract function fixture($arg): string;
);
}

#[Test, Condition(assert: 'self::processExecutionEnabled()'), Runtime(php: '>=7.2')]
#[Test, Condition(assert: 'self::processExecutionEnabled()')]
public function declaration_with_nullable_typehint() {
$r= $this->runInNewRuntime('
abstract class Base {
Expand All @@ -506,7 +506,7 @@ public abstract function fixture(string $arg);
);
}

#[Test, Condition(assert: 'self::processExecutionEnabled()'), Runtime(php: '>=7.1')]
#[Test, Condition(assert: 'self::processExecutionEnabled()')]
public function declaration_with_iterable_typehint() {
$r= $this->runInNewRuntime('
abstract class Base {
Expand All @@ -521,7 +521,7 @@ public abstract function fixture(iterable $args);
);
}

#[Test, Condition(assert: 'self::processExecutionEnabled()'), Runtime(php: '>=7.2')]
#[Test, Condition(assert: 'self::processExecutionEnabled()')]
public function declaration_with_object_typehint() {
$r= $this->runInNewRuntime('
abstract class Base {
Expand All @@ -536,7 +536,7 @@ public abstract function fixture(object $args);
);
}

#[Test, Condition(assert: 'self::processExecutionEnabled()'), Runtime(php: '>=7.1')]
#[Test, Condition(assert: 'self::processExecutionEnabled()')]
public function declaration_with_void_return() {
$r= $this->runInNewRuntime('
abstract class Base {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace lang\unittest;

use lang\{ClassLoader, ClassNotFoundException, Runnable, Throwable, XPClass};
use test\verify\Runtime;
use test\{Action, Assert, Expect, Test, Values};

class RuntimeClassDefinitionTest extends RuntimeTypeDefinitionTest {
Expand Down Expand Up @@ -142,7 +141,7 @@ public function closure_with_string_return_type() {
Assert::equals('1', $class->getMethod('fixture')->invoke($instance, [1]));
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function closure_with_void_return_type() {
$class= $this->define([], ['fixture' => function($a): void { }]);
$instance= $class->newInstance();
Expand Down
4 changes: 2 additions & 2 deletions src/test/php/lang/unittest/TypeOfTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public function function_with_primitive_return_type() {
Assert::equals(FunctionType::forName('function(): int'), typeof(eval('return function(): int { };')));
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function function_with_nullable_return_type() {
Assert::equals(FunctionType::forName('function(): ?string'), typeof(eval('return function(): ?string { };')));
}

#[Test, Runtime(php: '>=7.1')]
#[Test]
public function function_with_void_return_type() {
Assert::equals(FunctionType::forName('function(): void'), typeof(eval('return function(): void { };')));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/lang/unittest/TypeSyntaxTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function method($source) {
return ClassLoader::defineType(self::class.'Method'.(++$id), self::$spec, '{'.$source.'}')->getMethod('fixture');
}

#[Test, Runtime(php: '>=7.4')]
#[Test]
public function primitive_type() {
$d= $this->field('private string $fixture;');
Assert::equals(Primitive::$STRING, $d->getType());
Expand Down

0 comments on commit 1b7e0d7

Please sign in to comment.