PluginEntity example

Context::createDefaultContext()
        ));

        return new RequirementsValidator(
            $pluginRepo,
            $this->projectDir
        );
    }

    private function createPlugin(string $path): PluginEntity
    {
        $plugin = new PluginEntity();
        $plugin->setPath($path);
        $plugin->setManagedByComposer(false);
        $plugin->setVersion('1.0.0');
        $plugin->setComposerName('swag/' . (new CamelCaseToSnakeCaseNameConverter())->normalize(basename($path)));

        return $plugin;
    }
}

class PluginPostDeactivationFailedEventTest extends TestCase
{
    public function testEvent(): void
    {
        $activateContext = $this->createMock(ActivateContext::class);
        $exception = new \Exception('failed');
        $event = new PluginPostDeactivationFailedEvent(
            new PluginEntity(),
            $activateContext,
            $exception
        );
        static::assertInstanceOf(PluginLifecycleEvent::class$event);
        static::assertEquals($activateContext$event->getContext());
        static::assertEquals($exception$event->getException());
    }
}
private PluginListCommand $command;

    protected function setUp(): void
    {
        parent::setUp();
        $this->pluginRepoMock = $this->createMock(EntityRepository::class);
        $this->command = new PluginListCommand($this->pluginRepoMock);
    }

    public function testCommand(): void
    {
        $plugin1 = new PluginEntity();
        $plugin2 = new PluginEntity();

        $entities = [
            $plugin1,
            $plugin2,
        ];

        $plugin1->setUniqueIdentifier('1');
        $plugin1->assign([
            'active' => true,
            'installedAt' => new \DateTimeImmutable('2004-01-01T00:00:00.000001Z'),
            
$frwClient = $this->createMock(FirstRunWizardClient::class);
        $frwClient->expects(static::once())
            ->method('getRecommendations')
            ->with('us', 'payment', $this->context)
            ->willReturn($recommendations);

        $frwService = $this->createFirstRunWizardService(
            frwClient: $frwClient,
        );

        $installedPlugin = (new PluginEntity())->assign([
            'id' => Uuid::randomHex(),
            'name' => 'SwagPaypal',
            'active' => true,
            'installedAt' => new \DateTimeImmutable(),
        ]);

        $recommendations = $frwService->getRecommendations(
            new PluginCollection([$installedPlugin]),
            new AppCollection(),
            'us',
            'payment',
            
/** * @param array<string, mixed>[] $data */
    private function createPluginCollection(array $data): PluginCollection
    {
        $collection = new PluginCollection();
        $counter = \count($data);
        for ($i = 0; $i < $counter; ++$i) {
            if (!\array_key_exists('id', $data[$i])) {
                $data[$i]['id'] = Uuid::randomHex();
            }
            $collection->add((new PluginEntity())->assign($data[$i]));
        }

        return $collection;
    }

    /** * @param array<string, mixed>[] $pluginData * * @return EntitySearchResult<PluginCollection> */
    private function createPluginSearchResult(Context $context, array $pluginData): EntitySearchResult
    {
__DIR__,
            $this->createMock(AbstractStorefrontPluginConfigurationFactory::class),
            $handler,
            $this->createMock(ThemeLifecycleService::class)
        );

        $subscriber->pluginUpdate($event);
    }

    private function getPlugin(): PluginEntity
    {
        return (new PluginEntity())
            ->assign([
                'path' => (new \ReflectionClass(SwagTest::class))->getFileName(),
                'baseClass' => SwagTest::class,
            ]);
    }
}
$command = new PluginUpdateAllCommand($pluginService$pluginRepository$pluginLifecycleService);
        $command->setHelperSet(new HelperSet());

        $tester = new CommandTester($command);
        static::assertSame(Command::SUCCESS, $tester->execute(['--skip-asset-build' => true]));

        static::assertSame('Updated plugin Test2 from version 1.0.0 to version 1.0.1', trim($tester->getDisplay()));
    }

    private function createPlugin(string $name, bool $active = true, ?string $upgradeVersion = null): PluginEntity
    {
        $plugin = new PluginEntity();
        $plugin->setId(Uuid::randomHex());
        $plugin->setName($name);
        $plugin->setVersion('1.0.0');
        $plugin->setActive($active);
        $plugin->setUpgradeVersion($upgradeVersion);

        return $plugin;
    }
}
$activateContextMock = $this->createMock(ActivateContext::class);
        $activateContextMock->expects(static::once())->method('getContext')->willReturn($context);
        $eventMock = $this->createMock(PluginPostActivateEvent::class);
        $eventMock->expects(static::once())->method('getContext')->willReturn($activateContextMock);
        $eventMock->expects(static::never())->method('getPlugin');

        $this->pluginSubscriber->pluginPostActivate($eventMock);
    }

    public function testPluginPostActivate(): void
    {
        $pluginMock = new PluginEntity();
        $pluginMock->setPath('');
        $pluginMock->setBaseClass(FakePlugin::class);
        $eventMock = $this->createMock(PluginPostActivateEvent::class);
        $eventMock->expects(static::exactly(2))->method('getPlugin')->willReturn($pluginMock);
        $this->pluginSubscriber->pluginPostActivate($eventMock);
    }

    public function testPluginPostDeactivateFailed(): void
    {
        $pluginMock = new PluginEntity();
        $pluginMock->setPath('');
        

        $pluginManagementService = new PluginManagementService(
            '',
            $this->createMock(PluginZipDetector::class),
            $this->createMock(PluginExtractor::class),
            $this->createMock(PluginService::class),
            $this->createMock(Filesystem::class),
            $this->createMock(CacheClearer::class),
            new Client(['handler' => new MockHandler()])
        );

        $plugin = new PluginEntity();
        $plugin->setManagedByComposer(true);
        $plugin->setName('Test');

        static::expectException(PluginException::class);
        $pluginManagementService->deletePlugin($plugin, Context::createDefaultContext());
    }

    /** * @param Response[] $responses */
    private function createClient(array $responses = []): Client
    {
static::expectExceptionMessage('failed update');

        $this->pluginLifecycleService->deactivatePlugin($pluginEntityMock$context);
    }

    // ------ DeactivatePlugin -----
    // ++++++ privates +++++++
    public function testPluginBaseClassNotSet(): void
    {
        $pluginEntityMock = new PluginEntity();
        $pluginEntityMock->setBaseClass('MockPlugin');
        $context = Context::createDefaultContext();

        $this->kernelPluginCollectionMock->method('get')->willReturn(null);

        static::expectException(PluginBaseClassNotFoundException::class);

        $this->pluginLifecycleService->installPlugin($pluginEntityMock$context);
    }

    public function testPluginMigrationCollection(): void
    {
->fetchAllAssociative();

        foreach ($rules as $rule) {
            static::assertEquals(0, $rule['invalid']);
            static::assertNull($rule['payload']);
            static::assertNotNull($rule['id']);
        }
    }

    public static function dataProviderForTestPostEventNullsPayload(): array
    {
        $plugin = new PluginEntity();
        $plugin->setName('TestPlugin');
        $plugin->setBaseClass(RulePlugin::class);
        $plugin->setPath('');

        $context = Context::createDefaultContext();
        $rulePlugin = new RulePlugin(false, '');

        $collection = new MigrationCollection(
            new MigrationSource('asd', []),
            new MigrationRuntime(new NullConnection()new NullLogger()),
            new NullConnection()
        );
'path' => $plugin->getPath(),
            'autoload' => json_encode($plugin->getAutoload(), \JSON_THROW_ON_ERROR),
            'created_at' => $createdAt->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            'installed_at' => $installedAt ? $installedAt->format(Defaults::STORAGE_DATE_TIME_FORMAT) : null,
        ];

        $this->connection->insert('plugin', $data);
    }

    protected function getNotInstalledPlugin(): PluginEntity
    {
        $plugin = new PluginEntity();
        $plugin->assign([
            'id' => Uuid::randomHex(),
            'name' => 'SwagTest',
            'baseClass' => SwagTest::class,
            'version' => '1.0.1',
            'active' => false,
            'path' => __DIR__ . '/_fixture/plugins/SwagTest',
            'autoload' => ['psr-4' => ['SwagTest\\' => 'src/']],
            'createdAt' => new \DateTimeImmutable('2019-01-01'),
            'managedByComposer' => false,
        ]);

        
Home | Imprint | This part of the site doesn't use cookies.