1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php namespace League\Fractal\Test;
- use League\Fractal\ParamBag;
- use PHPUnit\Framework\TestCase;
- class ParamBagTest extends TestCase
- {
- public function testOldFashionedGet()
- {
- $params = new ParamBag(['one' => 'potato', 'two' => 'potato2']);
- $this->assertSame('potato', $params->get('one'));
- $this->assertSame('potato2', $params->get('two'));
- }
- public function testGettingValuesTheOldFashionedWayArray()
- {
- $params = new ParamBag(['one' => ['potato', 'tomato']]);
- $this->assertSame(['potato', 'tomato'], $params->get('one'));
- }
- public function testArrayAccess()
- {
- $params = new ParamBag(['foo' => 'bar', 'baz' => 'ban']);
- $this->assertInstanceOf('ArrayAccess', $params);
- $this->assertArrayHasKey('foo', $params);
- $this->assertTrue(isset($params['foo']));
- $this->assertSame('bar', $params['foo']);
- $this->assertSame('ban', $params['baz']);
- $this->assertNull($params['totallymadeup']);
- }
- /**
- * @expectedException \LogicException
- * @expectedExceptionMessage Modifying parameters is not permitted
- */
- public function testArrayAccessSetFails()
- {
- $params = new ParamBag(['foo' => 'bar']);
- $params['foo'] = 'someothervalue';
- }
- /**
- * @expectedException \LogicException
- * @expectedExceptionMessage Modifying parameters is not permitted
- */
- public function testArrayAccessUnsetFails()
- {
- $params = new ParamBag(['foo' => 'bar']);
- unset($params['foo']);
- }
- public function testObjectAccess()
- {
- $params = new ParamBag(['foo' => 'bar', 'baz' => 'ban']);
- $this->assertSame('bar', $params->foo);
- $this->assertSame('ban', $params->baz);
- $this->assertNull($params->totallymadeup);
- $this->assertTrue(isset($params->foo));
- }
- /**
- * @expectedException \LogicException
- * @expectedExceptionMessage Modifying parameters is not permitted
- */
- public function testObjectAccessSetFails()
- {
- $params = new ParamBag(['foo' => 'bar']);
- $params->foo = 'someothervalue';
- }
- /**
- * @expectedException \LogicException
- * @expectedExceptionMessage Modifying parameters is not permitted
- */
- public function testObjectAccessUnsetFails()
- {
- $params = new ParamBag(['foo' => 'bar']);
- unset($params->foo);
- }
- }
|