"Fossies" - the Fresh Open Source Software Archive

Member "symfony-3.4.28/src/Symfony/Component/Validator/Tests/Mapping/Cache/AbstractCacheTest.php" (28 May 2019, 2298 Bytes) of package /linux/www/symfony-3.4.28.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "AbstractCacheTest.php": 4.3.0_vs_4.3.1.

    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\Validator\Tests\Mapping\Cache;
   13 
   14 use PHPUnit\Framework\TestCase;
   15 use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
   16 use Symfony\Component\Validator\Mapping\ClassMetadata;
   17 
   18 abstract class AbstractCacheTest extends TestCase
   19 {
   20     /**
   21      * @var CacheInterface
   22      */
   23     protected $cache;
   24 
   25     public function testWrite()
   26     {
   27         $meta = $this->getMockBuilder(ClassMetadata::class)
   28             ->disableOriginalConstructor()
   29             ->setMethods(['getClassName'])
   30             ->getMock();
   31 
   32         $meta->expects($this->once())
   33             ->method('getClassName')
   34             ->will($this->returnValue('Foo\\Bar'));
   35 
   36         $this->cache->write($meta);
   37 
   38         $this->assertInstanceOf(
   39             ClassMetadata::class,
   40             $this->cache->read('Foo\\Bar'),
   41             'write() stores metadata'
   42         );
   43     }
   44 
   45     public function testHas()
   46     {
   47         $meta = $this->getMockBuilder(ClassMetadata::class)
   48             ->disableOriginalConstructor()
   49             ->setMethods(['getClassName'])
   50             ->getMock();
   51 
   52         $meta->expects($this->once())
   53             ->method('getClassName')
   54             ->will($this->returnValue('Foo\\Bar'));
   55 
   56         $this->assertFalse($this->cache->has('Foo\\Bar'), 'has() returns false when there is no entry');
   57 
   58         $this->cache->write($meta);
   59         $this->assertTrue($this->cache->has('Foo\\Bar'), 'has() returns true when the is an entry');
   60     }
   61 
   62     public function testRead()
   63     {
   64         $meta = $this->getMockBuilder(ClassMetadata::class)
   65             ->disableOriginalConstructor()
   66             ->setMethods(['getClassName'])
   67             ->getMock();
   68 
   69         $meta->expects($this->once())
   70             ->method('getClassName')
   71             ->will($this->returnValue('Foo\\Bar'));
   72 
   73         $this->assertFalse($this->cache->read('Foo\\Bar'), 'read() returns false when there is no entry');
   74 
   75         $this->cache->write($meta);
   76 
   77         $this->assertInstanceOf(ClassMetadata::class, $this->cache->read('Foo\\Bar'), 'read() returns metadata');
   78     }
   79 }