Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Google\Tests\Task; use Google\Tests\BaseTest; use Google\Task\Composer; u..
Decoded Output download
<?php
namespace Google\Tests\Task; use Google\Tests\BaseTest; use Google\Task\Composer; use Symfony\Component\Filesystem\Filesystem; use InvalidArgumentException; class ComposerTest extends BaseTest { private static $composerBaseConfig = array("repositories" => array(array("type" => "path", "url" => __DIR__ . "/../../..", "options" => array("symlink" => false))), "require" => array("google/apiclient" => "*"), "scripts" => array("pre-autoload-dump" => "Google\Task\Composer::cleanup"), "minimum-stability" => "dev"); public function testInvalidServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Google service "Foo" does not exist"); Composer::cleanup($this->createMockEvent(array("Foo"))); } public function testRelatePathServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Invalid Google service name "../YouTube""); Composer::cleanup($this->createMockEvent(array("../YouTube"))); } public function testEmptyServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Google service "" does not exist"); Composer::cleanup($this->createMockEvent(array(''))); } public function testWildcardServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Invalid Google service name "YouTube*""); Composer::cleanup($this->createMockEvent(array("YouTube*"))); } public function testRemoveServices() { $vendorDir = sys_get_temp_dir() . "/rand-" . rand(); $serviceDir = sprintf("%s/google/apiclient-services/src/", $vendorDir); $dirs = array("ServiceToKeep", "ServiceToDelete1", "ServiceToDelete2"); $files = array("ServiceToKeep/ServiceFoo.php", "ServiceToKeep.php", "SomeRandomFile.txt", "ServiceToDelete1/ServiceFoo.php", "ServiceToDelete1.php", "ServiceToDelete2/ServiceFoo.php", "ServiceToDelete2.php"); foreach ($dirs as $dir) { @mkdir($serviceDir . $dir, 511, true); } foreach ($files as $file) { touch($serviceDir . $file); } $print = "Removing 2 google services"; Composer::cleanup($this->createMockEvent(array("ServiceToKeep"), $vendorDir, $print), $this->createMockFilesystem(array("ServiceToDelete2", "ServiceToDelete2.php", "ServiceToDelete1", "ServiceToDelete1.php"), $serviceDir)); } private function createMockFilesystem(array $files, $serviceDir) { $mockFilesystem = $this->prophesize(Filesystem::class); foreach ($files as $filename) { $file = new \SplFileInfo($serviceDir . $filename); $mockFilesystem->remove($file->getRealPath())->shouldBeCalledTimes(1); } return $mockFilesystem->reveal(); } private function createMockEvent(array $servicesToKeep, $vendorDir = '', $print = null) { $mockPackage = $this->prophesize("Composer\Package\RootPackage"); $mockPackage->getExtra()->shouldBeCalledTimes(1)->willReturn(array("google/apiclient-services" => $servicesToKeep)); $mockConfig = $this->prophesize("Composer\Config"); $mockConfig->get("vendor-dir")->shouldBeCalledTimes(1)->willReturn($vendorDir); $mockComposer = $this->prophesize("Composer\Composer"); $mockComposer->getPackage()->shouldBeCalledTimes(1)->willReturn($mockPackage->reveal()); $mockComposer->getConfig()->shouldBeCalledTimes(1)->willReturn($mockConfig->reveal()); $mockEvent = $this->prophesize("Composer\Script\Event"); $mockEvent->getComposer()->shouldBeCalledTimes(1)->willReturn($mockComposer); if ($print) { $mockIO = $this->prophesize("Composer\IO\ConsoleIO"); $mockIO->write($print)->shouldBeCalledTimes(1); $mockEvent->getIO()->shouldBeCalledTimes(1)->willReturn($mockIO->reveal()); } return $mockEvent->reveal(); } public function testE2E() { $dir = $this->runComposerInstall(self::$composerBaseConfig + array("extra" => array("google/apiclient-services" => array("Drive", "YouTube")))); $serviceDir = $dir . "/vendor/google/apiclient-services/src"; $this->assertFileExists($serviceDir . "/Drive.php"); $this->assertFileExists($serviceDir . "/Drive"); $this->assertFileExists($serviceDir . "/YouTube.php"); $this->assertFileExists($serviceDir . "/YouTube"); $this->assertFileDoesNotExist($serviceDir . "/YouTubeReporting.php"); $this->assertFileDoesNotExist($serviceDir . "/YouTubeReporting"); passthru("rm -r " . $dir . "/vendor/google/apiclient-services"); $this->runComposerInstall(self::$composerBaseConfig + array("extra" => array("google/apiclient-services" => array("Drive", "YouTube", "YouTubeReporting"))), $dir); $this->assertFileExists($serviceDir . "/Drive.php"); $this->assertFileExists($serviceDir . "/Drive"); $this->assertFileExists($serviceDir . "/YouTube.php"); $this->assertFileExists($serviceDir . "/YouTube"); $this->assertFileExists($serviceDir . "/YouTubeReporting.php"); $this->assertFileExists($serviceDir . "/YouTubeReporting"); } public function testE2EBCTaskName() { $composerConfig = self::$composerBaseConfig + array("extra" => array("google/apiclient-services" => array("Drive"))); $composerConfig["scripts"]["pre-autoload-dump"] = "Google_Task_Composer::cleanup"; $dir = $this->runComposerInstall($composerConfig); $serviceDir = $dir . "/vendor/google/apiclient-services/src"; $this->assertFileExists($serviceDir . "/Drive.php"); $this->assertFileExists($serviceDir . "/Drive"); $this->assertFileDoesNotExist($serviceDir . "/YouTube.php"); $this->assertFileDoesNotExist($serviceDir . "/YouTube"); $this->assertFileDoesNotExist($serviceDir . "/YouTubeReporting.php"); $this->assertFileDoesNotExist($serviceDir . "/YouTubeReporting"); } public function testE2EOptimized() { $dir = $this->runComposerInstall(self::$composerBaseConfig + array("config" => array("optimize-autoloader" => true), "extra" => array("google/apiclient-services" => array("Drive")))); $classmap = (require_once $dir . "/vendor/composer/autoload_classmap.php"); $this->assertArrayHasKey("Google\Service\Drive", $classmap); $this->assertArrayNotHasKey("Google\Service\YouTube", $classmap); } private function runComposerInstall(array $composerConfig, $dir = null) { $composerJson = json_encode($composerConfig); if (is_null($dir)) { $dir = sys_get_temp_dir() . "/test-" . rand(); mkdir($dir); } file_put_contents($dir . "/composer.json", $composerJson); passthru("composer install -d " . $dir); return $dir; } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Google\Tests\Task; use Google\Tests\BaseTest; use Google\Task\Composer; use Symfony\Component\Filesystem\Filesystem; use InvalidArgumentException; class ComposerTest extends BaseTest { private static $composerBaseConfig = array("\x72\x65\x70\157\x73\151\164\x6f\x72\x69\x65\163" => array(array("\x74\x79\x70\x65" => "\x70\141\164\150", "\x75\162\154" => __DIR__ . "\x2f\56\56\x2f\x2e\56\57\56\x2e", "\157\160\x74\151\157\156\x73" => array("\x73\171\155\154\x69\156\x6b" => false))), "\x72\x65\x71\165\x69\x72\145" => array("\x67\x6f\x6f\147\154\x65\x2f\141\160\x69\x63\x6c\x69\x65\x6e\164" => "\x2a"), "\x73\143\162\x69\x70\164\163" => array("\x70\162\x65\x2d\x61\x75\164\157\x6c\157\141\x64\x2d\x64\165\155\x70" => "\x47\157\x6f\147\x6c\145\134\x54\x61\163\153\134\103\157\x6d\x70\157\163\145\162\72\x3a\x63\x6c\x65\141\156\x75\160"), "\x6d\x69\156\x69\155\x75\155\x2d\163\164\x61\x62\151\154\151\164\171" => "\x64\x65\166"); public function testInvalidServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("\x47\x6f\x6f\147\154\x65\x20\x73\145\162\x76\x69\143\x65\40\x22\x46\157\x6f\42\40\144\x6f\x65\163\x20\x6e\157\164\x20\x65\x78\x69\163\164"); Composer::cleanup($this->createMockEvent(array("\x46\157\x6f"))); } public function testRelatePathServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("\x49\156\166\141\x6c\x69\144\x20\107\x6f\157\x67\x6c\145\40\x73\x65\x72\x76\151\143\145\40\x6e\141\x6d\x65\x20\x22\x2e\56\57\x59\x6f\165\124\x75\x62\145\x22"); Composer::cleanup($this->createMockEvent(array("\56\56\57\131\x6f\x75\124\x75\142\145"))); } public function testEmptyServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("\x47\x6f\157\x67\154\x65\40\163\x65\x72\x76\151\143\x65\x20\x22\x22\x20\144\157\145\163\40\156\157\164\x20\145\x78\151\163\164"); Composer::cleanup($this->createMockEvent(array(''))); } public function testWildcardServiceName() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("\111\x6e\166\x61\154\x69\x64\x20\107\x6f\x6f\147\x6c\145\x20\163\x65\x72\x76\x69\x63\145\x20\156\141\155\145\x20\42\x59\157\165\124\165\142\145\x2a\42"); Composer::cleanup($this->createMockEvent(array("\x59\x6f\165\124\x75\x62\x65\52"))); } public function testRemoveServices() { $vendorDir = sys_get_temp_dir() . "\x2f\162\x61\x6e\x64\55" . rand(); $serviceDir = sprintf("\x25\163\x2f\147\157\157\147\x6c\145\x2f\141\x70\151\x63\154\151\145\156\164\55\x73\145\162\166\x69\143\x65\163\57\x73\162\x63\57", $vendorDir); $dirs = array("\123\145\x72\166\x69\x63\x65\x54\157\113\x65\x65\x70", "\x53\x65\x72\x76\x69\x63\145\124\x6f\104\x65\x6c\145\x74\145\x31", "\123\145\162\x76\x69\x63\145\x54\157\104\145\x6c\145\x74\x65\62"); $files = array("\x53\145\162\x76\151\143\x65\124\x6f\x4b\x65\145\160\57\x53\145\162\x76\151\x63\x65\x46\x6f\157\56\160\150\160", "\123\145\162\x76\151\143\x65\x54\x6f\113\145\145\x70\x2e\x70\150\x70", "\x53\x6f\x6d\145\122\141\156\x64\x6f\155\106\x69\154\145\x2e\x74\170\x74", "\123\x65\162\166\x69\x63\145\x54\x6f\x44\145\x6c\x65\164\x65\x31\57\x53\x65\x72\x76\x69\143\x65\106\157\x6f\x2e\160\x68\x70", "\x53\x65\162\x76\151\143\x65\124\157\104\145\154\145\164\x65\61\x2e\160\x68\160", "\123\145\x72\166\151\143\145\124\157\x44\145\x6c\x65\164\x65\x32\x2f\123\x65\162\166\x69\x63\145\x46\x6f\157\x2e\160\150\x70", "\x53\145\162\x76\x69\143\145\124\x6f\104\x65\154\x65\x74\145\62\x2e\x70\150\160"); foreach ($dirs as $dir) { @mkdir($serviceDir . $dir, 511, true); } foreach ($files as $file) { touch($serviceDir . $file); } $print = "\122\145\155\x6f\166\x69\156\147\40\62\x20\147\157\157\147\x6c\x65\x20\x73\145\162\166\x69\x63\x65\x73"; Composer::cleanup($this->createMockEvent(array("\x53\145\x72\x76\151\x63\145\124\157\x4b\x65\145\160"), $vendorDir, $print), $this->createMockFilesystem(array("\123\x65\162\166\151\x63\x65\124\x6f\104\145\154\x65\164\145\x32", "\x53\145\162\x76\151\x63\x65\124\x6f\104\145\154\145\x74\145\62\x2e\x70\x68\160", "\123\x65\x72\x76\151\143\x65\x54\x6f\x44\x65\x6c\x65\x74\x65\x31", "\123\145\x72\x76\151\x63\145\124\157\104\x65\x6c\x65\164\145\x31\x2e\x70\150\160"), $serviceDir)); } private function createMockFilesystem(array $files, $serviceDir) { $mockFilesystem = $this->prophesize(Filesystem::class); foreach ($files as $filename) { $file = new \SplFileInfo($serviceDir . $filename); $mockFilesystem->remove($file->getRealPath())->shouldBeCalledTimes(1); } return $mockFilesystem->reveal(); } private function createMockEvent(array $servicesToKeep, $vendorDir = '', $print = null) { $mockPackage = $this->prophesize("\103\x6f\x6d\x70\x6f\x73\145\162\134\x50\x61\x63\x6b\x61\147\x65\x5c\122\157\157\x74\x50\x61\143\153\x61\x67\145"); $mockPackage->getExtra()->shouldBeCalledTimes(1)->willReturn(array("\x67\157\157\x67\x6c\x65\57\x61\160\x69\143\x6c\151\145\x6e\164\x2d\163\145\x72\166\x69\143\145\x73" => $servicesToKeep)); $mockConfig = $this->prophesize("\x43\157\155\160\157\x73\x65\x72\x5c\x43\157\x6e\146\x69\147"); $mockConfig->get("\166\145\156\144\x6f\162\55\144\x69\162")->shouldBeCalledTimes(1)->willReturn($vendorDir); $mockComposer = $this->prophesize("\103\x6f\155\160\x6f\x73\145\x72\x5c\103\x6f\155\x70\157\x73\x65\162"); $mockComposer->getPackage()->shouldBeCalledTimes(1)->willReturn($mockPackage->reveal()); $mockComposer->getConfig()->shouldBeCalledTimes(1)->willReturn($mockConfig->reveal()); $mockEvent = $this->prophesize("\103\x6f\x6d\x70\157\163\145\162\134\x53\143\x72\x69\160\164\x5c\x45\x76\145\156\x74"); $mockEvent->getComposer()->shouldBeCalledTimes(1)->willReturn($mockComposer); if ($print) { $mockIO = $this->prophesize("\103\x6f\155\160\x6f\163\x65\x72\134\x49\117\134\x43\157\156\163\x6f\154\x65\111\117"); $mockIO->write($print)->shouldBeCalledTimes(1); $mockEvent->getIO()->shouldBeCalledTimes(1)->willReturn($mockIO->reveal()); } return $mockEvent->reveal(); } public function testE2E() { $dir = $this->runComposerInstall(self::$composerBaseConfig + array("\x65\170\164\162\141" => array("\147\157\x6f\147\154\x65\57\x61\x70\x69\x63\x6c\151\x65\x6e\164\x2d\163\145\162\166\x69\x63\145\x73" => array("\104\x72\151\166\x65", "\131\157\x75\124\x75\142\145")))); $serviceDir = $dir . "\57\166\x65\156\x64\x6f\x72\57\x67\x6f\157\147\154\x65\x2f\141\160\151\143\154\151\x65\156\x74\x2d\x73\x65\x72\x76\151\x63\x65\163\x2f\x73\162\x63"; $this->assertFileExists($serviceDir . "\57\104\162\151\166\145\x2e\160\x68\x70"); $this->assertFileExists($serviceDir . "\57\104\x72\151\166\145"); $this->assertFileExists($serviceDir . "\x2f\x59\157\x75\x54\165\142\x65\x2e\x70\150\x70"); $this->assertFileExists($serviceDir . "\x2f\x59\157\x75\124\x75\142\x65"); $this->assertFileDoesNotExist($serviceDir . "\57\131\157\165\x54\165\x62\145\122\145\160\x6f\162\x74\x69\x6e\x67\x2e\x70\x68\x70"); $this->assertFileDoesNotExist($serviceDir . "\57\131\157\165\x54\x75\x62\145\x52\x65\160\x6f\x72\x74\151\x6e\x67"); passthru("\162\155\40\55\x72\x20" . $dir . "\57\x76\x65\x6e\x64\x6f\x72\57\147\157\157\147\154\x65\57\141\160\151\x63\154\151\x65\x6e\x74\55\x73\x65\x72\x76\x69\143\145\163"); $this->runComposerInstall(self::$composerBaseConfig + array("\x65\170\164\x72\x61" => array("\147\157\x6f\x67\154\145\57\141\x70\x69\143\154\151\145\x6e\x74\x2d\x73\145\x72\x76\x69\143\145\163" => array("\104\x72\x69\x76\x65", "\131\157\165\x54\165\x62\145", "\131\157\165\x54\x75\142\x65\x52\145\160\x6f\x72\164\x69\156\147"))), $dir); $this->assertFileExists($serviceDir . "\57\x44\162\151\166\x65\56\x70\150\x70"); $this->assertFileExists($serviceDir . "\x2f\x44\x72\151\166\145"); $this->assertFileExists($serviceDir . "\57\x59\x6f\x75\x54\165\x62\x65\x2e\x70\x68\160"); $this->assertFileExists($serviceDir . "\57\x59\157\x75\124\x75\x62\145"); $this->assertFileExists($serviceDir . "\57\131\157\x75\x54\x75\142\x65\122\x65\160\x6f\x72\x74\x69\156\147\56\160\150\160"); $this->assertFileExists($serviceDir . "\x2f\x59\x6f\x75\x54\x75\142\145\x52\x65\160\157\162\x74\151\x6e\x67"); } public function testE2EBCTaskName() { $composerConfig = self::$composerBaseConfig + array("\145\x78\x74\x72\141" => array("\x67\x6f\x6f\147\154\x65\57\141\160\x69\x63\x6c\151\x65\156\164\55\163\145\x72\x76\151\143\x65\x73" => array("\104\x72\x69\x76\x65"))); $composerConfig["\x73\x63\162\151\x70\164\163"]["\160\x72\x65\x2d\x61\165\164\157\154\157\x61\144\x2d\x64\165\x6d\x70"] = "\107\157\157\147\x6c\x65\x5f\124\x61\x73\153\137\x43\x6f\155\x70\157\163\x65\x72\72\x3a\143\x6c\x65\141\x6e\x75\x70"; $dir = $this->runComposerInstall($composerConfig); $serviceDir = $dir . "\x2f\x76\x65\156\144\x6f\162\57\147\x6f\157\147\x6c\x65\x2f\x61\160\x69\143\154\151\x65\x6e\164\55\163\145\x72\x76\151\x63\145\163\x2f\x73\162\143"; $this->assertFileExists($serviceDir . "\57\104\x72\x69\x76\145\x2e\160\x68\x70"); $this->assertFileExists($serviceDir . "\57\x44\162\151\166\x65"); $this->assertFileDoesNotExist($serviceDir . "\57\x59\x6f\165\124\x75\142\145\56\160\x68\160"); $this->assertFileDoesNotExist($serviceDir . "\57\x59\x6f\x75\124\165\x62\145"); $this->assertFileDoesNotExist($serviceDir . "\x2f\x59\x6f\x75\124\x75\x62\145\122\x65\160\157\162\164\151\156\147\x2e\160\150\x70"); $this->assertFileDoesNotExist($serviceDir . "\57\131\157\165\124\x75\x62\x65\122\145\x70\x6f\x72\x74\151\x6e\147"); } public function testE2EOptimized() { $dir = $this->runComposerInstall(self::$composerBaseConfig + array("\x63\157\x6e\x66\151\147" => array("\157\160\164\x69\155\151\172\145\x2d\141\x75\164\x6f\x6c\x6f\141\144\x65\x72" => true), "\145\x78\164\x72\141" => array("\x67\157\157\147\x6c\145\57\141\x70\x69\x63\x6c\x69\145\156\x74\x2d\x73\145\x72\166\x69\143\145\x73" => array("\104\x72\151\x76\x65")))); $classmap = (require_once $dir . "\x2f\166\x65\156\144\x6f\x72\x2f\x63\x6f\x6d\160\x6f\x73\145\x72\x2f\141\165\164\x6f\154\157\x61\144\x5f\x63\154\x61\163\x73\x6d\x61\x70\x2e\160\150\x70"); $this->assertArrayHasKey("\x47\157\x6f\x67\x6c\145\134\x53\145\x72\166\151\x63\x65\134\104\162\151\166\x65", $classmap); $this->assertArrayNotHasKey("\107\x6f\x6f\147\x6c\145\134\123\x65\162\x76\x69\143\x65\x5c\x59\157\165\124\165\142\x65", $classmap); } private function runComposerInstall(array $composerConfig, $dir = null) { $composerJson = json_encode($composerConfig); if (is_null($dir)) { $dir = sys_get_temp_dir() . "\x2f\164\145\163\x74\55" . rand(); mkdir($dir); } file_put_contents($dir . "\57\143\x6f\155\160\x6f\x73\x65\x72\56\x6a\x73\x6f\156", $composerJson); passthru("\143\x6f\155\x70\x6f\x73\x65\162\x20\x69\156\x73\164\x61\154\x6c\40\55\144\x20" . $dir); return $dir; } }
Function Calls
None |
Stats
MD5 | bb33ca311b64f6ff8823da728c354de6 |
Eval Count | 0 |
Decode Time | 93 ms |