Brak opisu

MemoryDataCollectorTest.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\DataCollector;
  11. use Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. class MemoryDataCollectorTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testCollect()
  17. {
  18. $collector = new MemoryDataCollector();
  19. $collector->collect(new Request(), new Response());
  20. $this->assertInternalType('integer', $collector->getMemory());
  21. $this->assertInternalType('integer', $collector->getMemoryLimit());
  22. $this->assertSame('memory', $collector->getName());
  23. }
  24. /** @dataProvider getBytesConversionTestData */
  25. public function testBytesConversion($limit, $bytes)
  26. {
  27. $collector = new MemoryDataCollector();
  28. $method = new \ReflectionMethod($collector, 'convertToBytes');
  29. $method->setAccessible(true);
  30. $this->assertEquals($bytes, $method->invoke($collector, $limit));
  31. }
  32. public function getBytesConversionTestData()
  33. {
  34. return array(
  35. array('2k', 2048),
  36. array('2 k', 2048),
  37. array('8m', 8 * 1024 * 1024),
  38. array('+2 k', 2048),
  39. array('+2???k', 2048),
  40. array('0x10', 16),
  41. array('0xf', 15),
  42. array('010', 8),
  43. array('+0x10 k', 16 * 1024),
  44. array('1g', 1024 * 1024 * 1024),
  45. array('1G', 1024 * 1024 * 1024),
  46. array('-1', -1),
  47. array('0', 0),
  48. array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
  49. );
  50. }
  51. }