예제 #1
0
 /**
  * @inheritdoc
  */
 public function check($data)
 {
     if (is_null($data)) {
         return true;
     }
     return $this->asserter->check($data);
 }
예제 #2
0
 function _it_ensures_the_keys_types(AsserterInterface $asserterK1, AsserterInterface $asserterK2)
 {
     $asserterK1->check('val1')->willReturn(true);
     $asserterK1->check(1)->willReturn(false);
     $asserterK2->check('val2')->willReturn(true);
     $this->withKey('k1')->shouldReturn($this);
     $this->expected($asserterK1)->shouldReturn($this);
     $this->withKey('k2')->shouldReturn($this);
     $this->expected($asserterK2)->shouldReturn($this);
     $this->check(['k1' => 'val1', 'k2' => 'val2'])->shouldReturn(true);
     $this->check(['k1' => 1, 'k2' => 'val2'])->shouldReturn(false);
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 public function check($data)
 {
     if (!is_array($data)) {
         return false;
     }
     if (isset($this->min)) {
         if (count($data) < $this->min) {
             return false;
         }
     }
     if (isset($this->max)) {
         if (count($data) > $this->max) {
             return false;
         }
     }
     if (isset($this->valuesAsserter)) {
         foreach ($data as $value) {
             if (!$this->valuesAsserter->check($value)) {
                 return false;
             }
         }
     }
     foreach ($this->keys as $key => $asserter) {
         if (!is_null($asserter)) {
             if (!$asserter->check(@$data[$key])) {
                 return false;
             }
         }
     }
     if (!$this->otherKeysAllowed) {
         if (count(array_diff(array_keys($data), array_keys($this->keys))) > 0) {
             return false;
         }
     }
     return true;
 }
예제 #4
0
 function it_returns_false_if_at_least_one_asserter_returns_false(AsserterInterface $asserter2)
 {
     $asserter2->check(123)->willReturn(false);
     $this->check(123)->shouldReturn(false);
 }
예제 #5
0
 function it_validates_the_data(AsserterInterface $asserter)
 {
     $asserter->check('abc')->willReturn(true);
     $this->beConstructedWith('abc');
     $this->claim($asserter)->shouldReturn(true);
 }
예제 #6
0
 function it_returns_true_if_the_asserter_returns_so_for_non_null_values(AsserterInterface $asserter)
 {
     $asserter->check(123)->willReturn(true);
     $this->check(123)->shouldReturn(true);
 }