martin-helmich/phpunit-psr7-assert

View on GitHub
src/Constraint/UrlEncodedMatchesMany.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%
<?php
namespace Helmich\Psr7Assert\Constraint;

use PHPUnit\Framework\Constraint\Constraint;

class UrlEncodedMatchesMany extends Constraint
{
    /** @var UrlEncodedMatches[] */
    private $constraints = [];

    public function __construct(array $constraints)
    {
        foreach ($constraints as $key => $value) {
            $this->constraints[] = new UrlEncodedMatches($key, $value);
        }
    }

    protected function matches($other): bool
    {
        foreach ($this->constraints as $constraint) {
            if (!$constraint->evaluate($other, "", true)) {
                return false;
            }
        }

        return true;
    }


    public function toString(): string
    {
        return join(" and ", array_map(function(HasQueryParameterConstraint $c) {
            return $c->toString();
        }, $this->constraints));
    }
}