Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
13 / 13
StringLengthExpectation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
13 / 13
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 jsonSerialize
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getType
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 expect
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 getExpectation
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setExpectation
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
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 StringLengthExpectation
 *
 * @package DataExpectation
 * @author Tony Bogdanov <tonybogdanov@gmail.com>
 */
class StringLengthExpectation extends AbstractExpectation {
    use IndentTrait;
    /**
     * @var ExpectationInterface
     */
    protected $expectation;
    /**
     * StringLengthExpectation constructor.
     *
     * @param ExpectationInterface $expectation
     */
    public function __construct( ExpectationInterface $expectation ) {
        $this->setExpectation( $expectation );
    }
    /**
     * @return array
     */
    public function jsonSerialize(): array {
        return array_replace( parent::jsonSerialize(), [
            'expectationArguments' => [ $this->expectation ],
        ] );
    }
    /**
     * @return string
     */
    public function getType(): string {
        return
            "stringLength (\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( strlen( $data ), $path );
        } catch ( UnexpectedDataException $e ) {
            throw new UnexpectedDataException( $data, $this, $path, $e );
        }
        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;
    }
}