1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-17 21:38:14 +01:00
php-debugbar/tests/DebugBar/Tests/DebugBarTest.php

91 lines
3.2 KiB
PHP
Raw Normal View History

2013-08-14 21:37:24 +10:00
<?php
namespace DebugBar\Tests;
use DebugBar\DebugBar;
use DebugBar\Tests\DataCollector\MockCollector;
2013-08-14 22:12:33 +10:00
use DebugBar\Tests\Storage\MockStorage;
use DebugBar\RandomRequestIdGenerator;
2013-08-14 21:37:24 +10:00
class DebugBarTest extends DebugBarTestCase
{
public function testAddCollector()
{
$this->debugbar->addCollector($c = new MockCollector());
$this->assertTrue($this->debugbar->hasCollector('mock'));
$this->assertEquals($c, $this->debugbar->getCollector('mock'));
$this->assertContains($c, $this->debugbar->getCollectors());
}
/**
* @expectedException \DebugBar\DebugBarException
*/
public function testAddCollectorWithSameName()
{
$this->debugbar->addCollector(new MockCollector());
$this->debugbar->addCollector(new MockCollector());
}
public function testCollect()
{
$data = array('foo' => 'bar');
$this->debugbar->addCollector(new MockCollector($data));
$datac = $this->debugbar->collect();
$this->assertArrayHasKey('mock', $datac);
$this->assertEquals($datac['mock'], $data);
$this->assertEquals($datac, $this->debugbar->getData());
}
public function testArrayAccess()
{
$this->debugbar->addCollector($c = new MockCollector());
$this->assertEquals($c, $this->debugbar['mock']);
$this->assertTrue(isset($this->debugbar['mock']));
$this->assertFalse(isset($this->debugbar['foo']));
}
2013-08-14 22:12:33 +10:00
public function testStorage()
{
$s = new MockStorage();
$this->debugbar->setStorage($s);
$this->debugbar->addCollector(new MockCollector(array('foo')));
$data = $this->debugbar->collect();
$this->assertEquals($s->data[$this->debugbar->getCurrentRequestId()], $data);
}
2013-09-15 12:56:08 -04:00
public function testStackedData()
{
$_SESSION = array();
$this->debugbar->addCollector($c = new MockCollector(array('foo')));
$this->debugbar->stackData();
$this->assertArrayHasKey($ns = $this->debugbar->getStackDataSessionNamespace(), $_SESSION);
$this->assertArrayHasKey($id = $this->debugbar->getCurrentRequestId(), $_SESSION[$ns]);
$this->assertArrayHasKey('mock', $_SESSION[$ns][$id]);
$this->assertEquals($c->collect(), $_SESSION[$ns][$id]['mock']);
$this->assertTrue($this->debugbar->hasStackedData());
$data = $this->debugbar->getStackedData();
$this->assertArrayNotHasKey($ns, $_SESSION);
$this->assertArrayHasKey($id, $data);
$this->assertEquals(1, count($data));
$this->assertArrayHasKey('mock', $data[$id]);
$this->assertEquals($c->collect(), $data[$id]['mock']);
}
public function testStackedDataWithStorage()
{
2013-09-15 13:06:20 -04:00
$_SESSION = array();
2013-09-15 12:56:08 -04:00
$s = new MockStorage();
$this->debugbar->setStorage($s);
$this->debugbar->addCollector($c = new MockCollector(array('foo')));
$this->debugbar->stackData();
$id = $this->debugbar->getCurrentRequestId();
$this->assertNull($_SESSION[$this->debugbar->getStackDataSessionNamespace()][$id]);
$data = $this->debugbar->getStackedData();
$this->assertEquals($c->collect(), $data[$id]['mock']);
}
2013-08-14 21:37:24 +10:00
}