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