Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
14 / 14
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_config_test
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
14 / 14
15
100.00% covered (success)
100.00%
1 / 1
 test_offset_exists
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_offset_get
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 test_offset_get_missing
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 test_offset_set
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_offset_unset_fails
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_count
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 test_iterate
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 test_set_overwrite
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_set_new
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_set_atomic_overwrite
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_set_atomic_new
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_set_atomic_failure
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_increment
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 test_delete
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_config_test extends phpbb_test_case
15{
16    public function test_offset_exists()
17    {
18        $config = new \phpbb\config\config(array('foo' => 'bar'));
19
20        $this->assertTrue(isset($config['foo']));
21        $this->assertFalse(isset($config['foobar']));
22    }
23
24    public function test_offset_get()
25    {
26        $config = new \phpbb\config\config(array('foo' => 'bar'));
27        $this->assertEquals('bar', $config['foo']);
28    }
29
30    public function test_offset_get_missing()
31    {
32        $config = new \phpbb\config\config(array());
33        $this->assertEquals('', $config['foo']);
34    }
35
36    public function test_offset_set()
37    {
38        $config = new \phpbb\config\config(array());
39        $config['foo'] = 'x';
40        $this->assertEquals('x', $config['foo']);
41    }
42
43    public function test_offset_unset_fails()
44    {
45        $this->setExpectedTriggerError(E_USER_ERROR);
46        $config = new \phpbb\config\config(array('foo' => 'x'));
47        unset($config['foo']);
48    }
49
50    public function test_count()
51    {
52        $config = new \phpbb\config\config(array('foo' => 'bar'));
53        $this->assertEquals(1, count($config));
54    }
55
56    public function test_iterate()
57    {
58        $vars = array('foo' => '23', 'bar' => '42');
59        $config = new \phpbb\config\config($vars);
60
61        $count = 0;
62        foreach ($config as $key => $value)
63        {
64            $this->assertTrue(isset($vars[$key]));
65            $this->assertEquals($vars[$key], $value);
66
67            $count++;
68        }
69
70        $this->assertEquals(count($vars), $count);
71    }
72
73    public function test_set_overwrite()
74    {
75        $config = new \phpbb\config\config(array('foo' => 'x'));
76        $config->set('foo', 'bar');
77        $this->assertEquals('bar', $config['foo']);
78    }
79
80    public function test_set_new()
81    {
82        $config = new \phpbb\config\config(array());
83        $config->set('foo', 'bar');
84        $this->assertEquals('bar', $config['foo']);
85    }
86
87    public function test_set_atomic_overwrite()
88    {
89        $config = new \phpbb\config\config(array('foo' => 'bar'));
90        $this->assertTrue($config->set_atomic('foo', 'bar', '23'));
91        $this->assertEquals('23', $config['foo']);
92    }
93
94    public function test_set_atomic_new()
95    {
96        $config = new \phpbb\config\config(array());
97        $this->assertTrue($config->set_atomic('foo', false, '23'));
98        $this->assertEquals('23', $config['foo']);
99    }
100
101    public function test_set_atomic_failure()
102    {
103        $config = new \phpbb\config\config(array('foo' => 'bar'));
104        $this->assertFalse($config->set_atomic('foo', 'wrong', '23'));
105        $this->assertEquals('bar', $config['foo']);
106    }
107
108    public function test_increment()
109    {
110        $config = new \phpbb\config\config(array('foo' => '23'));
111        $config->increment('foo', 3);
112        $this->assertEquals(26, $config['foo']);
113        $config->increment('foo', 1);
114        $this->assertEquals(27, $config['foo']);
115    }
116
117    public function test_delete()
118    {
119        $config = new \phpbb\config\config(array('foo' => 'bar'));
120
121        $config->delete('foo');
122        $this->assertFalse(isset($config['foo']));
123    }
124}