コード例 #1
0
{
}
describe('Stubborn', function ($test) {
    describe('->run()', function ($test) {
        it('should execute and return the expected value for the provided function', function ($test) {
            $stubborn = new Stubborn();
            $result = $stubborn->run(function () {
                return 5;
            });
            expect($result)->to->be(5);
        });
        it('should execute and return all of the expected results for an array of provided functions', function ($test) {
            $stubborn = new Stubborn();
            $result = $stubborn->run(array(function () {
                return 5;
            }, function () {
                return 'Pineapple';
            }));
            expect(is_array($result))->to->be(true);
            expect(count($result))->to->be(2);
            expect($result[1])->to->be('Pineapple');
        });
    });
    describe('->catchExceptions()', function ($test) {
        it('should throw a non-handled exception', function ($test) {
            expect(function () use(&$test) {
                Stubborn::build()->run(function () {
                    throw new StubbornTestException('this should get thrown');
                });
            })->to->throw('Stubborn\\Tests\\StubbornTestException', 'this should get thrown');
        });
コード例 #2
0
ファイル: StubbornTest.php プロジェクト: gsdevme/stubborn
 /**
  * Tests that when the ->run returns a Stubburn response object it will correctly return it and end the loop
  */
 public function testResponseStubbornMockZeroRetries()
 {
     $stubbornAwareObject = $this->getStubbornMock();
     $stubbornResponseObject = $this->getStubbornResponseMock();
     $stubbornResponseObject->expects($this->once())->method('getData')->will($this->returnValue('{"status":"true"}'));
     $stubbornResponseObject->expects($this->once())->method('getHttpCode')->will($this->returnValue(200));
     // Run it 4 times
     $stubbornAwareObject->method('getRetryNumber')->will($this->returnValue(5));
     $stubbornAwareObject->method('getHttpActionRequest')->will($this->returnValue(false));
     $stubbornAwareObject->method('getExceptionActionRequest')->will($this->returnValue(false));
     $stubbornAwareObject->method('getRetryWaitSeconds')->will($this->returnValue(0));
     $stubbornAwareObject->expects($this->once())->method('run')->will($this->returnValue($stubbornResponseObject));
     $stubborn = new Stubborn($stubbornAwareObject);
     $response = $stubborn->run();
     $this->assertInstanceOf('Stubborn\\StubbornResponseInterface', $response);
     $this->assertEquals(0, $response->getRetryCount());
     $this->assertEquals('{"status":"true"}', $response->getData());
     $this->assertEquals(200, $response->getHttpCode());
 }