Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Failed Conditions
Push — live ( 05ca5f...631a24 )
by Dan
05:49
created

test_reset_when_set_directly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php declare(strict_types=1);
2
3
namespace SmrTest\Container;
4
5
use DI\ContainerBuilder;
6
use PHPUnit\Framework\TestCase;
7
use Smr\Container\ResettableContainer;
8
9
/**
10
 * @covers \Smr\Container\ResettableContainerTrait
11
 */
12
class ResettableContainerTraitTest extends TestCase {
13
14
	private ContainerBuilder $builder;
15
16
	protected function setUp(): void {
17
		$this->builder = new ContainerBuilder(ResettableContainer::class);
18
	}
19
20
	public function test_not_initialized_by_definition(): void {
21
		$this->builder->addDefinitions([
22
			'foo' => 'bar',
23
		]);
24
25
		// Unlike has(), entries are not initialized by definitions
26
		self::assertFalse($this->builder->build()->initialized('foo'));
0 ignored issues
show
Bug introduced by
The method initialized() does not exist on DI\Container. It seems like you code against a sub-type of said class. However, the method does not exist in DI\CompiledContainer. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
		self::assertFalse($this->builder->build()->/** @scrutinizer ignore-call */ initialized('foo'));
Loading history...
27
	}
28
29
	public function test_initialized_by_definition_after_get(): void {
30
		$this->builder->addDefinitions([
31
			'foo' => 'bar',
32
		]);
33
		$container = $this->builder->build();
34
		$container->get('foo');
35
36
		// Only once we get the entry for the first time is it initialized
37
		self::assertTrue($container->initialized('foo'));
38
	}
39
40
	public function test_initialized_when_set_directly(): void {
41
		$container = $this->builder->build();
42
		$container->set('foo', 'bar');
43
44
		// The entry is also initialized if set directly
45
		self::assertTrue($container->initialized('foo'));
46
	}
47
48
	public function test_not_initialized_when_unknown(): void {
49
		// Entry is not initialized in a default container
50
		self::assertFalse($this->builder->build()->initialized('foo'));
51
	}
52
53
	public function test_reset_with_definition(): void {
54
		$this->builder->addDefinitions([
55
			'foo' => 'bar',
56
		]);
57
		$container = $this->builder->build();
58
59
		// Sanity check the state of the entry prior to reset
60
		self::assertTrue($container->has('foo'));
61
		self::assertFalse($container->initialized('foo'));
62
63
		// Now initialize the entry, and sanity check the state again
64
		self::assertSame('bar', $container->get('foo'));
65
		self::assertTrue($container->has('foo'));
66
		self::assertTrue($container->initialized('foo'));
67
68
		// Then reset the entry
69
		$container->reset('foo');
0 ignored issues
show
Bug introduced by
The method reset() does not exist on DI\Container. It seems like you code against a sub-type of said class. However, the method does not exist in DI\CompiledContainer. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
		$container->/** @scrutinizer ignore-call */ 
70
              reset('foo');
Loading history...
70
71
		// It should still be gettable, but it is no longer initialized
72
		self::assertTrue($container->has('foo'));
73
		self::assertFalse($container->initialized('foo'));
74
		self::assertSame('bar', $container->get('foo'));
75
	}
76
77
	public function test_reset_when_set_directly(): void {
78
		$container = $this->builder->build();
79
		$container->set('foo', 'bar');
80
81
		// After resetting an entry that does not have a definition (i.e. it is
82
		// only set directly), it is no longer gettable.
83
		$container->reset('foo');
84
		self::assertFalse($container->has('foo'));
85
	}
86
87
}
88