14 use PHPUnit\Framework\TestCase;
34 protected function setUp()
38 'always' =>
'be happy',
39 'user.login' =>
'drak',
40 'csrf.token' => array(
52 $this->bag->initialize($this->array);
58 $this->array = array();
64 $bag->initialize($this->array);
65 $this->assertEquals($this->array, $this->bag->all());
66 $array = array(
'should' =>
'not stick');
67 $bag->initialize($array);
70 $this->assertEquals($this->array, $this->bag->all());
75 $this->assertEquals(
'_sf2', $this->bag->getStorageKey());
77 $this->assertEquals(
'test', $attributeBag->getStorageKey());
83 public function testHas($key, $value, $exists)
85 $this->assertEquals($exists, $this->bag->has($key));
91 public function testGet($key, $value, $expected)
93 $this->assertEquals($value, $this->bag->get($key));
98 $this->assertNull($this->bag->get(
'user2.login'));
99 $this->assertEquals(
'default', $this->bag->get(
'user2.login',
'default'));
105 public function testSet($key, $value, $expected)
107 $this->bag->set($key, $value);
108 $this->assertEquals($value, $this->bag->get($key));
113 $this->assertEquals($this->array, $this->bag->all());
115 $this->bag->set(
'hello',
'fabien');
116 $array = $this->array;
117 $array[
'hello'] =
'fabien';
118 $this->assertEquals($array, $this->bag->all());
124 $array[
'name'] =
'jack';
125 $array[
'foo.bar'] =
'beep';
126 $this->bag->replace($array);
127 $this->assertEquals($array, $this->bag->all());
128 $this->assertNull($this->bag->get(
'hello'));
129 $this->assertNull($this->bag->get(
'always'));
130 $this->assertNull($this->bag->get(
'user.login'));
135 $this->assertEquals(
'world', $this->bag->get(
'hello'));
136 $this->bag->remove(
'hello');
137 $this->assertNull($this->bag->get(
'hello'));
139 $this->assertEquals(
'be happy', $this->bag->get(
'always'));
140 $this->bag->remove(
'always');
141 $this->assertNull($this->bag->get(
'always'));
143 $this->assertEquals(
'drak', $this->bag->get(
'user.login'));
144 $this->bag->remove(
'user.login');
145 $this->assertNull($this->bag->get(
'user.login'));
150 $this->assertSame(
'cod', $this->bag->remove(
'category/fishing/first'));
155 $this->assertNull($this->bag->remove(
'foo/bar/baz'));
161 $this->assertEquals(array(), $this->bag->all());
167 array(
'hello',
'world',
true),
168 array(
'always',
'be happy',
true),
169 array(
'user.login',
'drak',
true),
170 array(
'csrf.token', array(
'a' =>
'1234',
'b' =>
'4321'),
true),
171 array(
'csrf.token/a',
'1234',
true),
172 array(
'csrf.token/b',
'4321',
true),
173 array(
'category', array(
'fishing' => array(
'first' =>
'cod',
'second' =>
'sole')),
true),
174 array(
'category/fishing', array(
'first' =>
'cod',
'second' =>
'sole'),
true),
175 array(
'category/fishing/missing/first',
null,
false),
176 array(
'category/fishing/first',
'cod',
true),
177 array(
'category/fishing/second',
'sole',
true),
178 array(
'category/fishing/missing/second',
null,
false),
179 array(
'user2.login',
null,
false),
180 array(
'never',
null,
false),
181 array(
'bye',
null,
false),
182 array(
'bye/for/now',
null,
false),