Skip to content

Commit c8a7a99

Browse files
committed
Fix tests
1 parent f8d3b3b commit c8a7a99

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

phpunit.xml.dist

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
7-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false"
3+
>
84
<testsuites>
95
<testsuite name="unit">
106
<directory>tests/Unit</directory>
@@ -16,4 +12,9 @@
1612
<php>
1713

1814
</php>
15+
<source>
16+
<include>
17+
<directory suffix=".php">src/</directory>
18+
</include>
19+
</source>
1920
</phpunit>

src/Providers/FlakyServiceProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace AaronFrancis\Flaky\Providers;
88

99
use Illuminate\Console\Events\CommandStarting;
10+
use Illuminate\Contracts\Console\Kernel;
1011
use Illuminate\Support\Env;
1112
use Illuminate\Support\Facades\Event;
1213
use Illuminate\Support\ServiceProvider;
@@ -29,6 +30,12 @@ public function register()
2930

3031
public function boot()
3132
{
32-
//
33+
// A workaround for testing due to a change in Laravel 10.4.1
34+
// https://github.com/laravel/framework/pull/46508
35+
if ($this->app->runningUnitTests()) {
36+
$this->app->booted(function () {
37+
app(Kernel::class)->rerouteSymfonyCommandEvents();
38+
});
39+
}
3340
}
3441
}

tests/Unit/ArbiterTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Exception;
1111
use Illuminate\Support\Carbon;
1212
use Illuminate\Support\Facades\Cache;
13+
use PHPUnit\Framework\Attributes\Test;
1314
use Throwable;
1415

1516
class ArbiterTest extends Base
@@ -31,7 +32,7 @@ protected function setCache($total, $consecutive, $deadline)
3132
], 60);
3233
}
3334

34-
/** @test */
35+
#[Test]
3536
public function it_should_throw_because_of_total()
3637
{
3738
$this->setCache(5, 0, now()->addMinute()->timestamp);
@@ -52,7 +53,7 @@ public function it_should_throw_because_of_total()
5253
$this->assertNotNull($e);
5354
}
5455

55-
/** @test */
56+
#[Test]
5657
public function it_should_throw_because_of_consecutive()
5758
{
5859
$this->setCache(0, 5, now()->addMinute()->timestamp);
@@ -73,7 +74,7 @@ public function it_should_throw_because_of_consecutive()
7374
$this->assertNotNull($e);
7475
}
7576

76-
/** @test */
77+
#[Test]
7778
public function it_should_throw_because_of_deadline()
7879
{
7980
Carbon::setTestNow();
@@ -111,7 +112,7 @@ public function it_should_throw_because_of_deadline()
111112
$a->handle(new Exception);
112113
}
113114

114-
/** @test */
115+
#[Test]
115116
public function an_allowed_failure_should_increment_both_and_carry_deadline()
116117
{
117118
$deadline = now()->addMinute()->timestamp;
@@ -128,7 +129,7 @@ public function an_allowed_failure_should_increment_both_and_carry_deadline()
128129
$this->assertEquals($deadline, $stats['deadline']);
129130
}
130131

131-
/** @test */
132+
#[Test]
132133
public function a_success_should_update_cache()
133134
{
134135
$this->setCache(2, 2, now()->timestamp);

tests/Unit/BasicTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
use Carbon\Carbon;
1212
use Exception;
1313
use Illuminate\Contracts\Debug\ExceptionHandler;
14+
use PHPUnit\Framework\Attributes\Test;
1415
use Throwable;
1516

1617
class BasicTest extends Base
1718
{
18-
/** @test */
19+
#[Test]
1920
public function it_works_with_no_exceptions()
2021
{
2122
$result = Flaky::make(__FUNCTION__)->run(function () {
@@ -29,7 +30,7 @@ public function it_works_with_no_exceptions()
2930
$this->assertNull($result->exception);
3031
}
3132

32-
/** @test */
33+
#[Test]
3334
public function failures_past_the_deadline_throw()
3435
{
3536
Carbon::setTestNow();
@@ -51,7 +52,7 @@ public function failures_past_the_deadline_throw()
5152
});
5253
}
5354

54-
/** @test */
55+
#[Test]
5556
public function too_many_consecutive_throw()
5657
{
5758
$flaky = Flaky::make(__FUNCTION__)->allowConsecutiveFailures(5);
@@ -71,7 +72,7 @@ public function too_many_consecutive_throw()
7172
});
7273
}
7374

74-
/** @test */
75+
#[Test]
7576
public function too_many_total_throw()
7677
{
7778
$flaky = Flaky::make(__FUNCTION__)->allowTotalFailures(5);
@@ -91,7 +92,7 @@ public function too_many_total_throw()
9192
});
9293
}
9394

94-
/** @test */
95+
#[Test]
9596
public function reported_instead_of_thrown()
9697
{
9798
$handler = new class
@@ -119,7 +120,7 @@ public function report(Throwable $e)
119120
$this->assertInstanceOf(Exception::class, $handler->reported);
120121
}
121122

122-
/** @test */
123+
#[Test]
123124
public function throws_for_unset_specific_exceptions()
124125
{
125126
$this->expectException(Exception::class);
@@ -134,7 +135,7 @@ public function throws_for_unset_specific_exceptions()
134135
});
135136
}
136137

137-
/** @test */
138+
#[Test]
138139
public function does_not_throws_for_specific_exceptions()
139140
{
140141
Carbon::setTestNow();
@@ -157,7 +158,7 @@ public function does_not_throws_for_specific_exceptions()
157158
});
158159
}
159160

160-
/** @test */
161+
#[Test]
161162
public function can_disable()
162163
{
163164
$this->expectException(Exception::class);
@@ -173,7 +174,7 @@ public function can_disable()
173174
config(['app.env' => 'production']);
174175
}
175176

176-
/** @test */
177+
#[Test]
177178
public function can_disable_locally()
178179
{
179180
Flaky::make(__FUNCTION__)
@@ -197,7 +198,7 @@ public function can_disable_locally()
197198
});
198199
}
199200

200-
/** @test */
201+
#[Test]
201202
public function can_handle_failures_ourselves()
202203
{
203204
$caught = null;
@@ -217,15 +218,15 @@ public function can_handle_failures_ourselves()
217218
$this->assertInstanceOf(Exception::class, $caught);
218219
}
219220

220-
/** @test */
221+
#[Test]
221222
public function can_pass_in_our_own_exception()
222223
{
223224
$result = Flaky::make(__FUNCTION__)->handle(new Exception('Oops'));
224225

225226
$this->assertInstanceOf(Result::class, $result);
226227
}
227228

228-
/** @test */
229+
#[Test]
229230
public function it_does_not_throw_for_non_exceptions_when_protections_are_bypassed()
230231
{
231232
$result = Flaky::make(__FUNCTION__)
@@ -238,7 +239,7 @@ public function it_does_not_throw_for_non_exceptions_when_protections_are_bypass
238239
$this->assertEquals(1, $result->value);
239240
}
240241

241-
/** @test */
242+
#[Test]
242243
public function handles_errors_as_well_as_exceptions()
243244
{
244245
$result = Flaky::make(__FUNCTION__)

tests/Unit/CommandTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
use Illuminate\Support\Env;
1010
use Illuminate\Support\Facades\Artisan;
1111
use Illuminate\Support\Facades\Event;
12+
use PHPUnit\Framework\Attributes\Test;
1213

1314
class CommandTest extends Base
1415
{
15-
/** @test */
16+
#[Test]
1617
public function varies_on_command()
1718
{
1819
Artisan::call('flaky:vary --arg=1 --flag');
@@ -34,7 +35,7 @@ public function varies_on_command()
3435
$this->assertNotEquals($one, $three);
3536
}
3637

37-
/** @test */
38+
#[Test]
3839
public function scheduled_only()
3940
{
4041
Artisan::call('flaky:scheduled');
@@ -53,7 +54,7 @@ public function scheduled_only()
5354
Env::getRepository()->set('IS_SCHEDULED', 0);
5455
}
5556

56-
/** @test */
57+
#[Test]
5758
public function env_var_gets_set()
5859
{
5960
$repo = Env::getRepository();

tests/Unit/RetryTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
use AaronFrancis\Flaky\Flaky;
1010
use AaronFrancis\Flaky\Tests\Support\TimeoutException;
1111
use Exception;
12+
use PHPUnit\Framework\Attributes\Test;
1213

1314
class RetryTest extends Base
1415
{
15-
/** @test */
16+
#[Test]
1617
public function it_will_retry()
1718
{
1819
$timesRun = 0;
@@ -34,7 +35,7 @@ public function it_will_retry()
3435
$this->assertEquals(1, $result->value);
3536
}
3637

37-
/** @test */
38+
#[Test]
3839
public function it_retries_a_particular_exception_as_single()
3940
{
4041
$timesRun = 0;
@@ -62,7 +63,7 @@ public function it_retries_a_particular_exception_as_single()
6263
$this->assertEquals(6, $timesRun);
6364
}
6465

65-
/** @test */
66+
#[Test]
6667
public function it_retries_a_particular_exception_as_array()
6768
{
6869
$timesRun = 0;

tests/Unit/SecondsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
namespace AaronFrancis\Flaky\Tests\Unit;
88

99
use AaronFrancis\Flaky\Flaky;
10+
use PHPUnit\Framework\Attributes\Test;
1011

1112
class SecondsTest extends Base
1213
{
13-
/** @test */
14+
#[Test]
1415
public function the_math_is_right()
1516
{
1617
$data = [

0 commit comments

Comments
 (0)