Skip to content

raph007/phpunit-doctrine-collections-asserts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPUnit Doctrine Collections asserts extensions

This extension allows asserting Doctrine Collections by given predicates in tests.

Installation

Install it via Composer:

composer require --dev raph007/phpunit-doctrine-collections-asserts

Usage

Use DoctrineCollectionsAsserts:

<?php

declare(strict_types=1);

namespace Raph\PHPUnitExtensions\DoctrineCollectionsAsserts\Tests;

use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
use Raph\PHPUnitExtensions\DoctrineCollectionsAsserts\DoctrineCollectionsAsserts;

class DoctrineCollectionsAssertsTest extends TestCase
{
    use DoctrineCollectionsAsserts;

    public function testAssertCollectionItemExistsThatSatisfiesPredicate(): void
    {
        $collection = new ArrayCollection(['key1' => 'value1', 'key2' => 'value2']);

        self::assertCollectionItemExistsThatSatisfiesPredicate(
            $collection,
            function (string $key, string $value) {
                return $key === 'key1' && $value === 'value1';
            }
        );
    }

    public function testAssertWholeCollectionSatisfiesPredicate(): void
        {
            $collection = new ArrayCollection([0, 8, 5, 3]);
    
            self::assertWholeCollectionSatisfiesPredicate(
                $collection,
                function (int $key, int $value) {
                    return $value >= 0;
                }
            );
        }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages