NullContext example



namespace Symfony\Component\Asset\Tests\Context;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\NullContext;

class NullContextTest extends TestCase
{
    public function testGetBasePath()
    {
        $nullContext = new NullContext();

        $this->assertEmpty($nullContext->getBasePath());
    }

    public function testIsSecure()
    {
        $nullContext = new NullContext();

        $this->assertFalse($nullContext->isSecure());
    }
}

class Package implements PackageInterface
{
    private VersionStrategyInterface $versionStrategy;
    private ContextInterface $context;

    public function __construct(VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
    {
        $this->versionStrategy = $versionStrategy;
        $this->context = $context ?? new NullContext();
    }

    public function getVersion(string $path): string
    {
        return $this->versionStrategy->getVersion($path);
    }

    public function getUrl(string $path): string
    {
        if ($this->isAbsoluteUrl($path)) {
            return $path;
        }
Home | Imprint | This part of the site doesn't use cookies.