Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
18 / 18 |
| ArrayDiffExpectation | |
100.00% |
1 / 1 |
|
100.00% |
8 / 8 |
9 | |
100.00% |
18 / 18 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| jsonSerialize | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getType | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| expect | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| getCompare | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| setCompare | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getExpectation | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| setExpectation | |
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 ArrayDiffExpectation | |
| * | |
| * @package DataExpectation | |
| * @author Tony Bogdanov <tonybogdanov@gmail.com> | |
| */ | |
| class ArrayDiffExpectation extends AbstractExpectation { | |
| use IndentTrait; | |
| /** | |
| * @var array | |
| */ | |
| protected $compare; | |
| /** | |
| * @var ExpectationInterface | |
| */ | |
| protected $expectation; | |
| /** | |
| * ArrayDiffExpectation constructor. | |
| * | |
| * @param array $compare | |
| * @param ExpectationInterface $expectation | |
| */ | |
| public function __construct( array $compare, ExpectationInterface $expectation ) { | |
| $this | |
| ->setCompare( array_values( $compare ) ) | |
| ->setExpectation( $expectation ); | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function jsonSerialize(): array { | |
| return array_replace( parent::jsonSerialize(), [ | |
| 'expectationArguments' => [ $this->compare, $this->expectation ], | |
| ] ); | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getType(): string { | |
| return | |
| "arrayDiff (\n" . | |
| $this->indent( json_encode( $this->getCompare() ) ) . ";\n" . | |
| $this->indent( $this->getExpectation()->getType() ) . ";\n" . | |
| ')'; | |
| } | |
| /** | |
| * @param $data | |
| * @param string|null $path | |
| * | |
| * @return $this | |
| * @throws UnexpectedDataException | |
| */ | |
| public function expect( $data, string $path = null ) { | |
| try { | |
| $this->getExpectation()->expect( array_values( array_diff( $data, $this->getCompare() ) ), $path ); | |
| } catch ( UnexpectedDataException $e ) { | |
| throw new UnexpectedDataException( $data, $this, $path, $e ); | |
| } | |
| return $this; | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function getCompare(): array { | |
| return $this->compare; | |
| } | |
| /** | |
| * @param array $compare | |
| * | |
| * @return $this | |
| */ | |
| public function setCompare( array $compare ) { | |
| $this->compare = $compare; | |
| return $this; | |
| } | |
| /** | |
| * @return ExpectationInterface | |
| */ | |
| public function getExpectation(): ExpectationInterface { | |
| return $this->expectation; | |
| } | |
| /** | |
| * @param ExpectationInterface $expectation | |
| * | |
| * @return $this | |
| */ | |
| public function setExpectation( ExpectationInterface $expectation ) { | |
| $this->expectation = $expectation; | |
| return $this; | |
| } | |
| } |