Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Convert newinstance to anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Apr 10, 2020
1 parent b5fbf5f commit c4aa5b4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/test/php/unittest/assert/unittest/AssertTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function execute_all_assertions() {
public function even_inside_allof_execution_stops_at_first_failure() {
try {
All::of(function() {
Assert::that('Hello')->isEmpty()->is(newinstance(Condition::class, [], [
'matches' => function($value) { throw new IllegalStateException('Unreachable'); }
]));
Assert::that('Hello')->isEmpty()->is(new class() extends Condition {
public function matches($value) { throw new IllegalStateException('Unreachable'); }
});
});
} catch (AssertionFailedError $expected) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class ConditionAssertionsTest extends AbstractAssertionsTest {

#[@test]
public function is_a_test() {
$this->assertVerified(Assertions::of('Test')->is(newinstance(Condition::class, [], [
'matches' => function($value) { return 'Test' === $value; }
])));
$this->assertVerified(Assertions::of('Test')->is(new class() extends Condition {
public function matches($value) { return 'Test' === $value; }
}));
}

#[@test]
public function is_not_a_test() {
$this->assertVerified(Assertions::of('Test')->isNot(newinstance(Condition::class, [], [
'matches' => function($value) { return 'Test' !== $value; }
])));
$this->assertVerified(Assertions::of('Test')->isNot(new class() extends Condition {
public function matches($value) { return 'Test' !== $value; }
}));
}
}
36 changes: 18 additions & 18 deletions src/test/php/unittest/assert/unittest/ExtractingTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ class ExtractingTest extends AbstractAssertionsTest {
protected function people() {
return [
[['id' => 1, 'name' => 'Test', 'age' => 42, 'department' => ['name' => 'Test']]],
[newinstance(Name::class, ['Test'], [
'id' => 1,
'name' => 'Test',
'age' => 42,
'department' => ['name' => 'Test']
])],
[newinstance(Name::class, ['Test'], [
'id' => function() { return 1; },
'name' => function() { return 'Test'; },
'age' => function() { return 42; },
'department' => function() { return ['name' => 'Test']; }
])],
[newinstance(Name::class, ['Test'], [
'getId' => function() { return 1; },
'getName' => function() { return 'Test'; },
'getAge' => function() { return 42; },
'getDepartment' => function() { return ['name' => 'Test']; }
])],
[new class('Test') extends Name {
public $id= 1;
public $name= 'Test';
public $age= 42;
public $department= ['name' => 'Test'];
}],
[new class('Test') extends Name {
public function id() { return 1; }
public function name() { return 'Test'; }
public function age() { return 42; }
public function department() { return ['name' => 'Test']; }
}],
[new class('Test') extends Name {
public function getId() { return 1; }
public function getName() { return 'Test'; }
public function getAge() { return 42; }
public function getDepartment() { return ['name' => 'Test']; }
}],
[new Person(1, 'Test', 42, ['name' => 'Test'])]
];
}
Expand Down

0 comments on commit c4aa5b4

Please sign in to comment.