dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'store'; } /** * testMultiProcess. */ public function testMultiProcess() { $fileCache = new FilesystemCache($this->dir, 'txt'); $breaker = new Breaker('github_api', ['ignore_exceptions' => true], $fileCache); $breaker2 = new Breaker('github_api', ['ignore_exceptions' => true], $fileCache); $breaker1FailureCount = 0; $breaker->addListener(CircuitEvents::FAILURE, function (CircuitEvent $event) use (&$breaker1FailureCount) { $breaker1FailureCount = $event->getCircuit()->getFailures(); }); $breaker2->addListener(CircuitEvents::FAILURE, function (CircuitEvent $event) use (&$breaker1FailureCount) { $this->assertEquals($breaker1FailureCount, $event->getCircuit()->getFailures()); }); $fn = function () { throw new CustomException("An error as occurred"); }; $breaker->protect($fn); $breaker2->protect($fn); } /** * testOpenBehavior. */ public function testOpenBehavior() { $breaker = new Breaker( 'exception breaker', ['exclude_exceptions' => ['Eljam\CircuitBreaker\Exception\CustomException']] ); $breaker->addListener(CircuitEvents::OPEN, function (CircuitEvent $event) { $this->assertInstanceOf('Eljam\CircuitBreaker\Circuit', $event->getCircuit()); }); $this->setExpectedException('Eljam\CircuitBreaker\Exception\CircuitOpenException'); $fn = function () { throw new CustomException("An error as occurred"); }; for ($i = 0; $i <= 5; $i++) { $breaker->protect($fn); } } /** * testHalfOpenBehavior. */ public function testHalfOpenBehavior() { $breaker = new Breaker( 'exception breaker', [ 'reset_timeout' => 1, 'ignore_exceptions' => true, ] ); $breaker->addListener(CircuitEvents::HALF_OPEN, function (CircuitEvent $event) { $this->assertInstanceOf('Eljam\CircuitBreaker\Circuit', $event->getCircuit()); }); $fn = function () { throw new CustomException("An error as occurred"); }; try { for ($i = 0; $i <= 5; $i++) { $breaker->protect($fn); } } catch (CircuitOpenException $e) { $this->assertSame('Eljam\CircuitBreaker\Exception\CircuitOpenException', get_class($e)); } sleep(2); $fnPass = function () { return 'ok'; }; $breaker->protect($fnPass); } /** * testGetTheResult. */ public function testGetTheResult() { $breaker = new Breaker('simple_echo'); $hello = 'eljam'; $fn = function () use ($hello) { return $hello; }; $result = $breaker->protect($fn); $this->assertSame($hello, $result); } /** * testIgnoreException. */ public function testIgnoreAllException() { $breaker = new Breaker( 'simple_echo', ['ignore_exceptions' => true] ); $hello = 'eljam'; $fn = function () use ($hello) { throw new CustomException("An error as occurred"); return $hello; }; $result = $breaker->protect($fn); $this->assertNull($result); } /** * testThrowCustomException. */ public function testThrowCustomException() { $breaker = new Breaker( 'custom_exception' ); $hello = 'eljam'; $this->setExpectedException('Eljam\CircuitBreaker\Exception\CustomException'); $fn = function () use ($hello) { throw new CustomException("An error as occurred"); return $hello; }; $breaker->protect($fn); } public function testAllowedException() { $breaker = new Breaker( 'allowed_exception', [ 'ignore_exceptions' => false, 'allowed_exceptions' => [ 'Eljam\CircuitBreaker\Exception\CustomException', ], ] ); $breaker1FailureCount = 0; $breaker->addListener(CircuitEvents::FAILURE, function (CircuitEvent $event) use (&$breaker1FailureCount) { $breaker1FailureCount = $event->getCircuit()->getFailures(); }); $fn = function () { throw new CustomException("An error as occurred"); }; try { $breaker->protect($fn); } catch (CustomException $e) { $this->assertInstanceOf('Eljam\CircuitBreaker\Exception\CustomException', $e); } $this->assertSame(0, $breaker1FailureCount); } public function tearDown() { @unlink($this->dir); } }__halt_compiler();----SIGNATURE:----qykZpZacYMOdNonDM4FyqT4o/LX1tBH7C5GTRKcG3xzQBBnUZ7+6YrXU7SwGTgB81Ijz9I6p8/U7O+AJGP0pbnHcyt2IbndNCm8ILAyMbBu9hq22W8JtL/vU0NsfFtrFD0wU/2UnrfD8YD/h7w7p1hEoIfWexS4J7dKbmHpS3R4dxEd1CPPsEh/ppfMrFZ678XGEdLBVCgkYg9WIhmE77VuL290QowWKs7DrFTlwVshkd8mcQs0KzeKXrLZ5d1HMt2OGaxV7Aw7HytnB0R8ZR+jDGatoNVRdy+YoZFlpRUnn6Zo0U9rhqXW0zJ7LOHp7dbYBw6gvoEHkiMoR3SFWCESPUglgPuVrWHtyRE8xp6YQZkhSD+JihHkiHkWdnWz003KdHJKVodFxGQeMGGD3kcOYDXlsA1UoRC9cCBrpqfDwMJ1g6pdHO4ZSNb0lO2C9IdtA+8pVX4OMWqna+YNzntUUJ9dkUJ0LAC44fsfdiDazVp02K++zgLWDiNqtnKYBJdGcSaG1N6ggnCn1+9pBeVCX13AjRjISYBB+/vWm6fbwTPb7bK69SIxPCIOLMQ2WyybAJ/nEcddK8zxzZj5waK2OBqd/MQ8w5/KZRgTthk5TJZK0DPX18NJyMRhH541C/xUaisbeaFW0o9Sy1eRcgz0iQ//fb+ccOP2sVZZwiWo=----ATTACHMENT:----OTkxOTMwMTA2NDI2MTg3MCAyMzAzNjI2NzY4ODU5NTU3IDMwNzI1MDIxNDg3NDk5MzM=