Beispiel #1
0
 public function testComplexSpec()
 {
     $graph = new SpecGraph();
     $graph->add('input', [], Spec::define(['sleepy' => Boa::boolean(), 'tennis_balls' => Boa::integer(), 'message' => Boa::either(Boa::string(), Boa::integer())], [], ['message']));
     $graph->add('allowedMessage', ['input'], Spec::define(['message' => [Boa::in(['hi', 'how are you?', 'you dumb']), Boa::in(['hi', 'how are you?', 'you are smart'])]], [], ['message']));
     $graph->add('validBallCount', ['input'], Spec::define(['tennis_balls' => Boa::between(1, 10)]));
     $graph->add('additionalBallProps', ['validBallCount'], Spec::define(['ball_color' => [Boa::string(), Boa::in(['blue', 'red', 'yellow'])]], [], ['ball_color']));
     $result = $graph->check(['sleepy' => true, 'tennis_balls' => 3, 'message' => 'hi', 'ball_color' => 'blue']);
     $this->assertTrue($result->passed());
     $result2 = $graph->check(['sleepy' => 1, 'tennis_balls' => 3]);
     $this->assertEqualsMatrix([[true, $result2->failed()], [1, count($result2->getFailed())], [['message'], $result2->getMissing()]]);
     $result3 = $graph->check(['sleepy' => true, 'tennis_balls' => -30, 'message' => 'hello']);
     $this->assertEqualsMatrix([[true, $result3->failed()], [2, count($result3->getFailed())], [[], $result3->getMissing()]]);
     $result4 = $graph->check(['sleepy' => true, 'tennis_balls' => 3, 'message' => 'how are you?']);
     $this->assertEqualsMatrix([[true, $result4->failed()], [0, count($result4->getFailed())], [['ball_color'], $result4->getMissing()]]);
     $result5 = $graph->check(['sleepy' => true, 'tennis_balls' => 3, 'message' => 'how are you?', 'ball_color' => 'liquid_gold']);
     $this->assertEqualsMatrix([[true, $result5->failed()], [1, count($result5->getFailed())], [[], $result5->getMissing()]]);
 }
 /**
  * Get the current offers for an ASIN from the Research API.
  *
  * @param string $asin
  * @param bool $noPaapi
  *
  * @return OffersResponse
  */
 public function getOffers($asin, $noPaapi = false)
 {
     Arguments::contain(Boa::string(), Boa::boolean())->check($asin, $noPaapi);
     $query = ['format' => 'pretty'];
     if ($noPaapi) {
         $query['nopaapi'] = true;
     }
     return (new OffersResponseFactory())->makeFromResponse($this->client->get(vsprintf('/v1/offers/%s', [$asin]), ['query' => $query]));
 }
Beispiel #3
0
 /**
  * Return the first value if the condition is true, otherwise, return the
  * second.
  *
  * @param bool $biased
  * @param mixed|Closure $one
  * @param mixed|Closure $other
  *
  * @return mixed
  */
 public static function firstBias($biased, $one, $other)
 {
     Arguments::define(Boa::boolean(), Boa::any(), Boa::any())->check($biased, $one, $other);
     if ($biased) {
         return static::thunk($one);
     }
     return static::thunk($other);
 }
 public function testFireWithValidSpec()
 {
     $laravelJob = m::mock(LaravelJob::class);
     $laravelJob->shouldReceive('delete')->atLeast()->once();
     $job = new Job();
     $job->state = JobState::QUEUED;
     $job->data = json_encode(['omg' => false, 'why_not' => 'because']);
     $handler = $this->expectationsToMock(BaseTask::class, [$this->on('fire', [$job, m::type(JobSchedulerInterface::class)]), $this->on('getSpec', [], Spec::define(['omg' => Boa::boolean()], ['yes' => 'please'], ['why_not'])), $this->on('isSelfDeleting', [], false)]);
     $impersonator = new Impersonator();
     $impersonator->mock(JobRepositoryInterface::class, function (MockInterface $mock) use($job) {
         $mock->shouldReceive('find')->with(1337)->atLeast()->once()->andReturn($job);
         $mock->shouldReceive('started')->with($job, m::type('string'))->atLeast()->once();
         $mock->shouldReceive('complete')->with($job)->atLeast()->once();
     });
     $impersonator->mock(HandlerResolverInterface::class, function (MockInterface $mock) use($job, $handler) {
         $mock->shouldReceive('resolve')->with($job)->atLeast()->once()->andReturn($handler);
     });
     /** @var RunTaskCommand $command */
     $command = $impersonator->make(RunTaskCommand::class);
     $command->fire($laravelJob, ['job_id' => 1337]);
 }