You are here

class FlashBagTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/Session/Flash/FlashBagTest.php \Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest

FlashBagTest.

@author Drak <drak@zikula.org>

Hierarchy

  • class \Symfony\Component\HttpFoundation\Tests\Session\Flash\FlashBagTest extends \Symfony\Component\HttpFoundation\Tests\Session\Flash\PHPUnit_Framework_TestCase

Expanded class hierarchy of FlashBagTest

File

vendor/symfony/http-foundation/Tests/Session/Flash/FlashBagTest.php, line 21

Namespace

Symfony\Component\HttpFoundation\Tests\Session\Flash
View source
class FlashBagTest extends \PHPUnit_Framework_TestCase {

  /**
   * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
   */
  private $bag;

  /**
   * @var array
   */
  protected $array = array();
  protected function setUp() {
    parent::setUp();
    $this->bag = new FlashBag();
    $this->array = array(
      'notice' => array(
        'A previous flash message',
      ),
    );
    $this->bag
      ->initialize($this->array);
  }
  protected function tearDown() {
    $this->bag = null;
    parent::tearDown();
  }
  public function testInitialize() {
    $bag = new FlashBag();
    $bag
      ->initialize($this->array);
    $this
      ->assertEquals($this->array, $bag
      ->peekAll());
    $array = array(
      'should' => array(
        'change',
      ),
    );
    $bag
      ->initialize($array);
    $this
      ->assertEquals($array, $bag
      ->peekAll());
  }
  public function testGetStorageKey() {
    $this
      ->assertEquals('_sf2_flashes', $this->bag
      ->getStorageKey());
    $attributeBag = new FlashBag('test');
    $this
      ->assertEquals('test', $attributeBag
      ->getStorageKey());
  }
  public function testGetSetName() {
    $this
      ->assertEquals('flashes', $this->bag
      ->getName());
    $this->bag
      ->setName('foo');
    $this
      ->assertEquals('foo', $this->bag
      ->getName());
  }
  public function testPeek() {
    $this
      ->assertEquals(array(), $this->bag
      ->peek('non_existing'));
    $this
      ->assertEquals(array(
      'default',
    ), $this->bag
      ->peek('not_existing', array(
      'default',
    )));
    $this
      ->assertEquals(array(
      'A previous flash message',
    ), $this->bag
      ->peek('notice'));
    $this
      ->assertEquals(array(
      'A previous flash message',
    ), $this->bag
      ->peek('notice'));
  }
  public function testGet() {
    $this
      ->assertEquals(array(), $this->bag
      ->get('non_existing'));
    $this
      ->assertEquals(array(
      'default',
    ), $this->bag
      ->get('not_existing', array(
      'default',
    )));
    $this
      ->assertEquals(array(
      'A previous flash message',
    ), $this->bag
      ->get('notice'));
    $this
      ->assertEquals(array(), $this->bag
      ->get('notice'));
  }
  public function testAll() {
    $this->bag
      ->set('notice', 'Foo');
    $this->bag
      ->set('error', 'Bar');
    $this
      ->assertEquals(array(
      'notice' => array(
        'Foo',
      ),
      'error' => array(
        'Bar',
      ),
    ), $this->bag
      ->all());
    $this
      ->assertEquals(array(), $this->bag
      ->all());
  }
  public function testSet() {
    $this->bag
      ->set('notice', 'Foo');
    $this->bag
      ->set('notice', 'Bar');
    $this
      ->assertEquals(array(
      'Bar',
    ), $this->bag
      ->peek('notice'));
  }
  public function testHas() {
    $this
      ->assertFalse($this->bag
      ->has('nothing'));
    $this
      ->assertTrue($this->bag
      ->has('notice'));
  }
  public function testKeys() {
    $this
      ->assertEquals(array(
      'notice',
    ), $this->bag
      ->keys());
  }
  public function testPeekAll() {
    $this->bag
      ->set('notice', 'Foo');
    $this->bag
      ->set('error', 'Bar');
    $this
      ->assertEquals(array(
      'notice' => array(
        'Foo',
      ),
      'error' => array(
        'Bar',
      ),
    ), $this->bag
      ->peekAll());
    $this
      ->assertTrue($this->bag
      ->has('notice'));
    $this
      ->assertTrue($this->bag
      ->has('error'));
    $this
      ->assertEquals(array(
      'notice' => array(
        'Foo',
      ),
      'error' => array(
        'Bar',
      ),
    ), $this->bag
      ->peekAll());
  }

  /**
   * @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::getIterator
   * @group legacy
   */
  public function testLegacyGetIterator() {
    $flashes = array(
      'hello' => 'world',
      'beep' => 'boop',
      'notice' => 'nope',
    );
    foreach ($flashes as $key => $val) {
      $this->bag
        ->set($key, $val);
    }
    $i = 0;
    foreach ($this->bag as $key => $val) {
      $this
        ->assertEquals(array(
        $flashes[$key],
      ), $val);
      ++$i;
    }
    $this
      ->assertEquals(count($flashes), $i);
    $this
      ->assertCount(0, $this->bag
      ->all());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlashBagTest::$array protected property
FlashBagTest::$bag private property
FlashBagTest::setUp protected function
FlashBagTest::tearDown protected function
FlashBagTest::testAll public function
FlashBagTest::testGet public function
FlashBagTest::testGetSetName public function
FlashBagTest::testGetStorageKey public function
FlashBagTest::testHas public function
FlashBagTest::testInitialize public function
FlashBagTest::testKeys public function
FlashBagTest::testLegacyGetIterator public function @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::getIterator @group legacy
FlashBagTest::testPeek public function
FlashBagTest::testPeekAll public function
FlashBagTest::testSet public function