PHP Classes

File: tests/ArrayStringParameterTest.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Parameter   tests/ArrayStringParameterTest.php   Download  
File: tests/ArrayStringParameterTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Parameter
Validate function parameters with PHP attributes
Author: By
Last change:
Date: 20 days ago
Size: 2,050 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\Tests;

use
Chevere\Parameter\ArrayStringParameter;
use
InvalidArgumentException;
use
PHPUnit\Framework\TestCase;
use function
Chevere\Parameter\string;

final class
ArrayStringParameterTest extends TestCase
{
    public function
testConstruct(): void
   
{
       
$parameter = new ArrayStringParameter();
       
$this->assertCount(0, $parameter->parameters());
    }

    public function
testWithRequired(): void
   
{
       
$parameter = new ArrayStringParameter();
       
$foo = string();
       
$parameterWith = $parameter->withRequired(
           
foo: $foo
       
);
       
$this->assertNotSame($parameter, $parameterWith);
       
$this->assertCount(1, $parameterWith->parameters());
       
$this->assertSame($foo, $parameterWith->parameters()->get('foo'));
       
$this->assertTrue($parameterWith->parameters()->requiredKeys()->contains('foo'));
    }

    public function
testWithOptional(): void
   
{
       
$parameter = new ArrayStringParameter();
       
$foo = string();
       
$parameterWith = $parameter->withOptional(
           
foo: $foo
       
);
       
$this->assertNotSame($parameter, $parameterWith);
       
$this->assertCount(1, $parameterWith->parameters());
       
$this->assertSame($foo, $parameterWith->parameters()->get('foo'));
       
$this->assertTrue($parameterWith->parameters()->optionalKeys()->contains('foo'));
    }

    public function
testAssertCompatible(): void
   
{
       
$test = new ArrayStringParameter();
       
$test->assertCompatible(new ArrayStringParameter());
       
$notCompatible = (new ArrayStringParameter())
            ->
withRequired(
               
foo: string()
            );
       
$this->expectException(InvalidArgumentException::class);
       
$test->assertCompatible($notCompatible);
    }
}