noPluginFoundInZip example

#[Package('core')] class PluginZipDetector
{
    /** * @return PluginManagementService::PLUGIN|PluginManagementService::APP */
    public function detect(string $zipFilePath): string
    {
        try {
            $archive = ZipUtils::openZip($zipFilePath);
        } catch (PluginExtractionException $e) {
            throw PluginException::noPluginFoundInZip($zipFilePath);
        }

        try {
            return match (true) {
                $this->isPlugin($archive) => PluginManagementService::PLUGIN,
                $this->isApp($archive) => PluginManagementService::APP,
                default => throw PluginException::noPluginFoundInZip($zipFilePath)
            };
        } finally {
            $archive->close();
        }
    }


    public function testCannotExtractZipOpenError(): void
    {
        $e = PluginException::cannotExtractZipOpenError('/some/problematic.zip');

        static::assertEquals(PluginException::CANNOT_EXTRACT_ZIP, $e->getErrorCode());
    }

    public function testNoPluginFoundInZip(): void
    {
        $e = PluginException::noPluginFoundInZip('/no/plugin.zip');

        static::assertEquals(PluginException::NO_PLUGIN_IN_ZIP, $e->getErrorCode());
    }

    public function testStoreNotAvailable(): void
    {
        $e = PluginException::storeNotAvailable();

        static::assertEquals(PluginException::STORE_NOT_AVAILABLE, $e->getErrorCode());
    }
}
Home | Imprint | This part of the site doesn't use cookies.