Skip to content

Commit 9bbd7bc

Browse files
daniel-gluDaniel Smallwood
andauthored
Throw specific exceptions for already invoked or invalid runtime (#1)
Co-authored-by: Daniel Smallwood <daniel.smallwood@ea.com>
1 parent 2600d4b commit 9bbd7bc

4 files changed

Lines changed: 40 additions & 7 deletions

File tree

src/BackgroundProcessing.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
namespace CrowdStar\BackgroundProcessing;
2121

2222
use Closure;
23+
use CrowdStar\BackgroundProcessing\Exception\AlreadyInvokedException;
24+
use CrowdStar\BackgroundProcessing\Exception\InvalidEnvironmentException;
2325
use CrowdStar\BackgroundProcessing\Timer\AbstractTimer;
2426

2527
/**
@@ -47,17 +49,17 @@ class BackgroundProcessing
4749
/**
4850
* @param bool $stopTiming Stop timing the current transaction or not before starting processing tasks in background
4951
* @return void
50-
* @throws Exception
52+
* @throws AlreadyInvokedException|InvalidEnvironmentException
5153
*/
5254
public static function run(bool $stopTiming = false)
5355
{
5456
if (self::isInvoked()) {
55-
throw new Exception('background process invoked already');
57+
throw new AlreadyInvokedException('background process invoked already');
5658
}
5759
self::setInvoked(true);
5860

5961
if (!is_callable('fastcgi_finish_request')) {
60-
throw new Exception('background process invokable under PHP-FPM only');
62+
throw new InvalidEnvironmentException('background process invokable under PHP-FPM only');
6163
}
6264
session_write_close();
6365
fastcgi_finish_request();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
declare(strict_types=1);
1919

20-
namespace CrowdStar\BackgroundProcessing;
20+
namespace CrowdStar\BackgroundProcessing\Exception;
2121

2222
/**
2323
* Class Exception
2424
*
2525
* @package CrowdStar\BackgroundProcessing
2626
*/
27-
class Exception extends \Exception
27+
class AlreadyInvokedException extends \Exception
2828
{
2929
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**************************************************************************
3+
* Copyright 2018 Glu Mobile Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*************************************************************************/
17+
18+
declare(strict_types=1);
19+
20+
namespace CrowdStar\BackgroundProcessing\Exception;
21+
22+
/**
23+
* Class Exception
24+
*
25+
* @package CrowdStar\BackgroundProcessing
26+
*/
27+
class InvalidEnvironmentException extends \Exception
28+
{
29+
}

tests/unit/BasicTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
namespace CrowdStar\BackgroundProcessing;
2121

22+
use CrowdStar\BackgroundProcessing\Exception\AlreadyInvokedException;
23+
use CrowdStar\BackgroundProcessing\Exception\InvalidEnvironmentException;
2224
use PHPUnit\Framework\TestCase;
2325

2426
/**
@@ -97,7 +99,7 @@ public static function dataRun(): array
9799
/**
98100
* @dataProvider dataRun
99101
* @covers BackgroundProcessing::run()
100-
* @throws \CrowdStar\BackgroundProcessing\Exception
102+
* @throws AlreadyInvokedException|InvalidEnvironmentException
101103
*/
102104
public function testRun(int $expected, array $closures, string $message): void
103105
{
@@ -113,7 +115,7 @@ public function testRun(int $expected, array $closures, string $message): void
113115
*/
114116
public function testRunWhenInvokedAlready(): void
115117
{
116-
$this->expectException(Exception::class);
118+
$this->expectException(AlreadyInvokedException::class);
117119
$this->expectExceptionMessage('background process invoked already');
118120

119121
BackgroundProcessing::run();

0 commit comments

Comments
 (0)