You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
laravel-logs-layer/tests/Constraints/InstanceOfAtLeastOne.php

44 lines
870 B
PHP

<?php
namespace Ae3\LaravelLogsLayer\Tests\Constraints;
use PHPUnit\Framework\Constraint\Constraint;
class InstanceOfAtLeastOne extends Constraint
{
/**
* @var string
*/
protected string $expectedClass;
/**
* @param string $expectedClass
*/
public function __construct(string $expectedClass)
{
parent::__construct();
$this->expectedClass = $expectedClass;
}
/**
* @param $other
* @return bool
*/
public function matches($other): bool
{
foreach ($other as $item) {
if ($item instanceof $this->expectedClass) {
return true;
}
}
return false;
}
/**
* @return string
*/
public function toString(): string
{
return "contains at least one instance of '{$this->expectedClass}'";
}
}