Code Coverage  | 
      ||||||||||
Classes and Traits  | 
       Functions and Methods  | 
       Lines  | 
      ||||||||
| Total |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       6 / 6  | 
       CRAP |         | 
       100.00%  | 
       18 / 18  | 
      
| MapExpectation |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       6 / 6  | 
       10 |         | 
       100.00%  | 
       18 / 18  | 
      
| __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  | 
       4 |         | 
       100.00%  | 
       7 / 7  | 
      |||
| 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 MapExpectation | |
| * | |
| * @package DataExpectation | |
| * @author Tony Bogdanov <tonybogdanov@gmail.com> | |
| */ | |
| class MapExpectation extends AbstractExpectation { | |
| use IndentTrait; | |
| /** | |
| * @var ExpectationInterface[] | |
| */ | |
| protected $expectations; | |
| /** | |
| * MapExpectation constructor. | |
| * | |
| * @param ExpectationInterface[] $expectations | |
| */ | |
| public function __construct( array $expectations ) { | |
| $this->setExpectations( $expectations ); | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function jsonSerialize(): array { | |
| return array_replace( parent::jsonSerialize(), [ | |
| 'expectationArguments' => [ $this->expectations ], | |
| ] ); | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getType(): string { | |
| $result = "map {\n"; | |
| foreach ( $this->getExpectations() as $key => $expectation ) { | |
| $result .= $this->indent( $key . ' = ' . $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 $key => $expectation ) { | |
| try { | |
| $expectation->expect( | |
| $data[ $key ], | |
| $path ? $path . '.' . $key : null | |
| ); | |
| } catch ( UnexpectedDataException $e ) { | |
| throw new UnexpectedDataException( $data, $this, $path, $e ); | |
| } | |
| } | |
| return $this; | |
| } | |
| /** | |
| * @return ExpectationInterface[] | |
| */ | |
| public function getExpectations(): array { | |
| return $this->expectations; | |
| } | |
| /** | |
| * @param ExpectationInterface[] $expectations | |
| * | |
| * @return $this | |
| */ | |
| public function setExpectations( array $expectations ) { | |
| $this->expectations = $expectations; | |
| return $this; | |
| } | |
| } |