Skip to content

Commit 86ce2a7

Browse files
authored
Merge pull request #50 from xp-forge/refactor/use-throws-assertion
Use throws assertion
2 parents ee104df + b778fc7 commit 86ce2a7

File tree

5 files changed

+14
-31
lines changed

5 files changed

+14
-31
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"php" : ">=7.0.0"
1212
},
1313
"require-dev" : {
14-
"xp-framework/unittest": "^11.0 | ^10.0"
14+
"xp-framework/unittest": "^11.1"
1515
},
1616
"autoload" : {
1717
"files" : ["src/main/php/autoload.php"]

src/test/php/util/data/unittest/SequenceIteratorTest.class.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ public function may_iterate_sequence_based_on_a_fixed_enumerable_more_than_once(
5656
public function cannot_iterate_sequence_based_on_a_streamed_enumerable_more_than_once($input) {
5757
$seq= Sequence::of($input);
5858
$this->iterated($seq->iterator());
59-
try {
59+
60+
Assert::throws(CannotReset::class, function() use($seq) {
6061
$this->iterated($seq->iterator());
61-
$this->fail('No exception raised', null, 'util.data.CannotReset');
62-
} catch (CannotReset $expected) {
63-
// OK
64-
}
62+
});
6563
}
6664

6765
#[@test, @values('util.data.unittest.Enumerables::validArrays')]

src/test/php/util/data/unittest/SequenceTest.class.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ class SequenceTest extends AbstractSequenceTest {
1616
*/
1717
protected function assertNotTwice($seq, $func) {
1818
$func($seq);
19-
try {
19+
Assert::throws(CannotReset::class, function() use($seq, $func) {
2020
$func($seq);
21-
$this->fail('No exception raised', null, CannotReset::class);
22-
} catch (CannotReset $expected) {
23-
// OK
24-
}
21+
});
2522
}
2623

2724
#[@test]

src/test/php/util/data/unittest/TraversalOfTest.class.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ public function exceptions_from_rewind_are_wrapped_in_cannot_reset($class) {
3636
]));
3737
$fixture->rewind();
3838

39-
try {
39+
Assert::throws(CannotReset::class, function() use($fixture) {
4040
$fixture->rewind();
41-
$this->fail('Expected exception not caught', null, CannotReset::class);
42-
} catch (CannotReset $expected) {
43-
// OK
44-
}
41+
});
4542
}
4643

4744
#[@test]
@@ -55,11 +52,8 @@ public function exceptions_during_iteration_are_left_untouched() {
5552
]));
5653
$fixture->rewind();
5754

58-
try {
55+
Assert::throws(IllegalStateException::class, function() use($fixture) {
5956
$fixture->current();
60-
$this->fail('Expected exception not caught', null, IllegalStateException::class);
61-
} catch (IllegalStateException $expected) {
62-
// OK
63-
}
57+
});
6458
}
6559
}

src/test/php/util/data/unittest/YieldingOfTest.class.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,18 @@ public function cannot_rewind_after_rewind($generator) {
2424
$fixture= new YieldingOf($generator());
2525
$fixture->rewind();
2626

27-
try {
27+
Assert::throws(CannotReset::class, function() use($fixture) {
2828
$fixture->rewind();
29-
$this->fail('Expected exception not caught', null, CannotReset::class);
30-
} catch (CannotReset $expected) {
31-
// OK
32-
}
29+
});
3330
}
3431

3532
#[@test, @values('fixtures')]
3633
public function cannot_rewind_after_complete_iteration($generator) {
3734
$fixture= new YieldingOf($generator());
3835
iterator_to_array($fixture);
3936

40-
try {
37+
Assert::throws(CannotReset::class, function() use($fixture) {
4138
$fixture->rewind();
42-
$this->fail('Expected exception not caught', null, CannotReset::class);
43-
} catch (CannotReset $expected) {
44-
// OK
45-
}
39+
});
4640
}
4741
}

0 commit comments

Comments
 (0)