Issues (36)

tests/Helpers/HasWriteOnlyProperties.php (1 issue)

Severity
1
<?php
2
3
/**
4
 * PHP: Nelson Martell Library file
5
 *
6
 * Copyright © 2017-2021 Nelson Martell (http://nelson6e65.github.io)
7
 *
8
 * Licensed under The MIT License (MIT)
9
 * For full copyright and license information, please see the LICENSE
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright 2017-2021 Nelson Martell
13
 * @link      http://nelson6e65.github.io/php_nml/
14
 * @since     0.7.0
15
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
16
 * */
17
18
declare(strict_types=1);
19
20
namespace NelsonMartell\Test\Helpers;
21
22
use BadMethodCallException;
23
use NelsonMartell\IStrictPropertiesContainer;
24
use PHPUnit\Framework\TestCase;
25
26
/**
27
 * Split of ImplementsIStrictPropertiesContainer, for classes implementing any write-only property.
28
 *
29
 * @author Nelson Martell <[email protected]>
30
 * @since 0.7.0
31
 * */
32
trait HasWriteOnlyProperties
33
{
34
    /**
35
     */
36
    abstract public function testImplementsIStrictPropertiesContainerInterface(): void;
37
38
    abstract public function writeonlyPropertiesProvider(): array;
39
40
    /**
41
     * @dataProvider writeonlyPropertiesProvider
42
     *
43
     * @param IStrictPropertiesContainer $obj
44
     * @param string                     $property
45
     * @param mixed                      $value
46
     */
47
    public function testWriteonlyPropertiesAreWritablesAreNotReadables(
48
        IStrictPropertiesContainer $obj,
49
        string $property,
50
        $value
51
    ): void {
52
        $obj->$property = $value;
53
        /** @var TestCase $this */
54
        $this->addToAssertionCount(1);
55
56
        $this->expectException(BadMethodCallException::class);
57
        $actual = $obj->$property;
0 ignored issues
show
The assignment to $actual is dead and can be removed.
Loading history...
58
    }
59
}
60