PHP code example of sven / laravel-collection-testing-helpers

1. Go to this page and download the library: Download sven/laravel-collection-testing-helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sven / laravel-collection-testing-helpers example snippets




use Sven\LaravelCollectionTestingHelpers\Helpers;
use Illuminate\Foundation\Testing\TestCase;

class ExampleTest extends TestCase
{
    public function test_collections()
    {
        Helpers::enable();
        
        collect(['apple', 'pear', 'banana'])
            ->assertContains('apple')
            ->assertNotContains('orange');
    }

    public function test_callable_filtering()
    {
        Helpers::enable();
        
        collect(['apple', 'pear', 'banana'])
            ->assertContains(fn ($fruit) => $fruit === 'pear')
            ->assertNotContains(fn ($fruit) => $fruit === 'kiwi');
    }

    public function test_keyed_collections()
    {
        Helpers::enable();
        
        collect([['name' => 'apple'], ['name' => 'pear'], ['name' => 'banana']])
            ->assertContains('name', 'apple')
            ->assertNotContains('name', 'grape');
    }
}