Code Coverage  | 
      ||||||||||
Classes and Traits  | 
       Functions and Methods  | 
       Lines  | 
      ||||||||
| Total |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       6 / 6  | 
       CRAP |         | 
       100.00%  | 
       16 / 16  | 
      
| OrExpectation |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       6 / 6  | 
       9 |         | 
       100.00%  | 
       16 / 16  | 
      
| __construct |         | 
       100.00%  | 
       1 / 1  | 
       1 |         | 
       100.00%  | 
       2 / 2  | 
      |||
| jsonSerialize |         | 
       100.00%  | 
       1 / 1  | 
       1 |         | 
       100.00%  | 
       2 / 2  | 
      |||
| getType |         | 
       100.00%  | 
       1 / 1  | 
       2 |         | 
       100.00%  | 
       4 / 4  | 
      |||
| expect |         | 
       100.00%  | 
       1 / 1  | 
       3 |         | 
       100.00%  | 
       5 / 5  | 
      |||
| getExpectations |         | 
       100.00%  | 
       1 / 1  | 
       1 |         | 
       100.00%  | 
       1 / 1  | 
      |||
| setExpectations |         | 
       100.00%  | 
       1 / 1  | 
       1 |         | 
       100.00%  | 
       2 / 2  | 
      |||
| <?php | |
| /** | |
| * Copyright (c) Tony Bogdanov <tonybogdanov@gmail.com> | |
| * | |
| * For the full copyright and license information, please view the LICENSE | |
| * file that was distributed with this source code. | |
| */ | |
| namespace DataExpectation; | |
| use DataExpectation\Exceptions\UnexpectedDataException; | |
| use DataExpectation\Traits\IndentTrait; | |
| /** | |
| * Class OrExpectation | |
| * | |
| * @package DataExpectation | |
| * @author Tony Bogdanov <tonybogdanov@gmail.com> | |
| */ | |
| class OrExpectation extends AbstractExpectation { | |
| use IndentTrait; | |
| /** | |
| * @var ExpectationInterface[] | |
| */ | |
| protected $expectations; | |
| /** | |
| * OrExpectation constructor. | |
| * | |
| * @param ExpectationInterface $left | |
| * @param ExpectationInterface $right | |
| * @param ExpectationInterface ...$extra | |
| */ | |
| public function __construct( | |
| ExpectationInterface $left, | |
| ExpectationInterface $right, | |
| ExpectationInterface ...$extra | |
| ) { | |
| $this->setExpectations( array_merge( [ $left, $right ], $extra ) ); | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function jsonSerialize(): array { | |
| return array_replace( parent::jsonSerialize(), [ | |
| 'expectationArguments' => $this->expectations, | |
| ] ); | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getType(): string { | |
| $result = "or (\n"; | |
| foreach ( $this->getExpectations() as $expectation ) { | |
| $result .= $this->indent( $expectation->getType() . ";\n" ); | |
| } | |
| return $result . ')'; | |
| } | |
| /** | |
| * @param $data | |
| * @param string|null $path | |
| * | |
| * @return $this | |
| * @throws UnexpectedDataException | |
| */ | |
| public function expect( $data, string $path = null ) { | |
| foreach ( $this->getExpectations() as $expectation ) { | |
| try { | |
| $expectation->expect( $data, $path ); | |
| return $this; | |
| } catch ( UnexpectedDataException $e ) {} | |
| } | |
| throw new UnexpectedDataException( $data, $this, $path ); | |
| } | |
| /** | |
| * @return ExpectationInterface[] | |
| */ | |
| public function getExpectations(): array { | |
| return $this->expectations; | |
| } | |
| /** | |
| * @param ExpectationInterface[] $expectations | |
| * | |
| * @return $this | |
| */ | |
| public function setExpectations( array $expectations ) { | |
| $this->expectations = $expectations; | |
| return $this; | |
| } | |
| } |