assertIsResource example

$currentMedia = new MediaEntity();
        $currentMedia->setId(Uuid::randomHex());
        $currentMedia->setPrivate($isPrivate);

        $mediaSearchResult = $this->createMock(EntitySearchResult::class);
        $mediaSearchResult->method('get')->willReturn($currentMedia);
        $mediaSearchResult->method('getEntities')->willReturn($mediaWithRelatedFileName);
        $this->mediaRepository->method('search')->willReturn($mediaSearchResult);

        $file = tmpfile();
        static::assertIsResource($file);
        $tempMeta = stream_get_meta_data($file);
        $mediaFile = new MediaFile($tempMeta['uri'], 'image/png', 'png', 0);

        $context = Context::createDefaultContext(new AdminApiSource(Uuid::randomHex()));
        $mediaId = Uuid::randomHex();

        $message = new GenerateThumbnailsMessage();
        $message->setMediaIds([$mediaId]);

        if (Feature::isActive('v6.6.0.0')) {
            $message->setContext($context);
        }
$filesystem,
            $filesystem,
            $kernel,
            new StaticKernelPluginLoader($this->createMock(ClassLoader::class)),
            $this->createMock(CacheInvalidator::class),
            $this->createMock(AbstractAppLoader::class),
            new ParameterBag(['shopware.filesystem.asset.type' => 's3'])
        );

        $filesystem->method('writeStream')
            ->willReturnCallback(function Dstring $path$stream) {
                static::assertIsResource($stream);
                // Some flysystem adapters automatically close the stream e.g. google adapter                 fclose($stream);

                return true;
            });

        $assetService->copyAssetsFromBundle('ExampleBundle');
    }

    public function testCopyAssetsWithoutApp(): void
    {
        
if ($this->mediaDirCreated) {
            rmdir($projectDir . '/public/media');
            $this->mediaDirCreated = false;
        }
    }

    public function testFetchRequestData(): void
    {
        $tempFile = (string) tempnam(sys_get_temp_dir(), '');

        $content = fopen(self::TEST_IMAGE, 'rb');
        static::assertIsResource($content);

        $request = new Request([][][][][][]$content);
        $request->query->set('extension', 'png');

        $fileSize = filesize(self::TEST_IMAGE);
        $request->headers = new HeaderBag();
        $request->headers->set('content-length', (string) $fileSize);

        try {
            $this->fileFetcher->fetchRequestData(
                $request,
                

class CopyBatchTest extends TestCase
{
    public function testCopy(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());

        $tmpFile = sys_get_temp_dir() . '/' . uniqid('test', true);
        file_put_contents($tmpFile, 'test');

        $sourceFile = fopen($tmpFile, 'rb');
        static::assertIsResource($sourceFile);
        CopyBatch::copy($fsnew CopyBatchInput($tmpFile['test.txt'])new CopyBatchInput($sourceFile['test2.txt']));

        static::assertTrue($fs->fileExists('test.txt'));
        static::assertTrue($fs->fileExists('test2.txt'));
        static::assertSame('test', $fs->read('test.txt'));
        static::assertSame('test', $fs->read('test2.txt'));

        unlink($tmpFile);
    }

    public function testConstructor(): void
    {


    public function testWritingAndFormatting()
    {
        $host = 'tcp://127.0.0.1:9999';
        $handler = new ServerLogHandler($host, Logger::INFO, false);
        $handler->pushProcessor(new ProcessIdProcessor());

        $infoRecord = RecordFactory::create(Logger::INFO, 'My info message', 'app', datetime: new \DateTimeImmutable('2013-05-29 16:21:54'));

        $socket = stream_socket_server($host$errno$errstr);
        $this->assertIsResource($socketsprintf('Server start failed on "%s": %s %s.', $host$errstr$errno));

        $this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');

        $sockets = [(int) $socket => $socket];
        $write = [];

        for ($i = 0; $i < 10; ++$i) {
            $read = $sockets;
            stream_select($read$write$write, null);

            foreach ($read as $stream) {
                
public function testGetContentWorksTwiceInDefaultMode()
    {
        $req = new Request();
        $this->assertEquals('', $req->getContent());
        $this->assertEquals('', $req->getContent());
    }

    public function testGetContentReturnsResource()
    {
        $req = new Request();
        $retval = $req->getContent(true);
        $this->assertIsResource($retval);
        $this->assertEquals('', fread($retval, 1));
        $this->assertTrue(feof($retval));
    }

    public function testGetContentReturnsResourceWhenContentSetInConstructor()
    {
        $req = new Request([][][][][][], 'MyContent');
        $resource = $req->getContent(true);

        $this->assertIsResource($resource);
        $this->assertEquals('MyContent', stream_get_contents($resource));
    }
'mediaFolderId' => $folderId,
                ],
            ],
            $this->context
        );
        $media = $this->mediaRepository->search(new Criteria([$mediaId])$this->context)->get($mediaId);
        static::assertInstanceOf(MediaEntity::class$media);

        $mediaPath = $this->getContainer()->get(UrlGeneratorInterface::class)->getRelativeMediaUrl($media);

        $file = fopen(self::FIXTURE_FILE, 'rb');
        static::assertIsResource($file);
        $this->getPublicFilesystem()->writeStream($mediaPath$file);

        $this->folderRepository->delete([['id' => $folderId]]$this->context);

        static::assertEquals(0, $this->folderRepository->search(new Criteria([$folderId])$this->context)->getTotal());
        static::assertEquals(0, $this->mediaRepository->search(new Criteria([$mediaId])$this->context)->getTotal());

        $this->runWorker();

        static::assertFalse($this->getPublicFilesystem()->has($mediaPath));
    }

    
'delimiter' => ';',
                'enclosure' => '"',
                'sourceEntity' => $data['sourceEntity'],
                'mapping' => $lookupMapping,
            ],
        ], Context::createDefaultContext());

        // prepare csv file for guessing         $filePath = tempnam(sys_get_temp_dir(), '');
        if (!isset($data['emptyFile']) || $data['emptyFile'] === false) {
            $file = fopen($filePath, 'wb');
            static::assertIsResource($file);
            fwrite($file(string) $data['csvHeader']);
            fclose($file);
        }
        $uploadedFile = new UploadedFile($filePath, 'test', $data['fileType'] ?? 'text/csv');

        try {
            $guessedMapping = $this->mappingService->getMappingFromTemplate(
                Context::createDefaultContext(),
                $uploadedFile,
                $data['sourceEntity']
            );
        }
$progress = $this->export($context, ProductDefinition::ENTITY_NAME, null, null, $profile->getId());

        static::assertImportExportSucceeded($progress$this->getInvalidLogContent($progress->getInvalidRecordsLogId()));

        $filesystem = $this->getContainer()->get('shopware.filesystem.private');
        $logfile = $this->getLogEntity($progress->getLogId())->getFile();
        static::assertInstanceOf(ImportExportFileEntity::class$logfile);
        $csv = $filesystem->read($logfile->getPath());
        static::assertIsString($csv);
        $resource = fopen('data://text/plain;base64,' . base64_encode($csv), 'rb');
        static::assertIsResource($resource);
        $reader = new CsvReader();
        $record = null;
        foreach ($reader->read(new Config([][][])$resource, 0) as $row) {
            $record = $row;

            break;
        }

        static::assertNotNull($record);
        static::assertEquals('foo', $record['custom_field_1']);
        static::assertEquals('23', $record['custom_field_2']);
        
$this->assertIsString($typed_data->getString());
    $this->assertEquals(0, $typed_data->validate()->count());
    $typed_data->setValue(NULL);
    $this->assertNull($typed_data->getValue(), 'Email wrapper is null-able.');
    $this->assertEquals(0, $typed_data->validate()->count());
    $typed_data->setValue('invalidATexample.com');
    $this->assertEquals(1, $typed_data->validate()->count(), 'Validation detected invalid value.');

    // Binary type.     $typed_data = $this->createTypedData(['type' => 'binary']$files[0]->getFileUri());
    $this->assertInstanceOf(BinaryInterface::class$typed_data);
    $this->assertIsResource($typed_data->getValue());
    $this->assertEquals(0, $typed_data->validate()->count());
    // Try setting by URI.     $typed_data->setValue($files[1]->getFileUri());
    $this->assertEquals(fgets(fopen($files[1]->getFileUri(), 'r'))fgets($typed_data->getValue()), 'Binary value was changed.');
    $this->assertIsString($typed_data->getString());
    $this->assertEquals(0, $typed_data->validate()->count());
    // Try setting by resource.     $typed_data->setValue(fopen($files[2]->getFileUri(), 'r'));
    $this->assertEquals(fgets($typed_data->getValue())fgets(fopen($files[2]->getFileUri(), 'r')), 'Binary value was changed.');
    $this->assertIsString($typed_data->getString());
    $this->assertEquals(0, $typed_data->validate()->count());
    

    public function testDetectType($fileData): void
    {
        $fileService = new FileService(
            $this->getContainer()->get('shopware.filesystem.private'),
            $this->getContainer()->get('import_export_file.repository')
        );

        $filePath = $fileData['file'];
        $file = fopen($filePath, 'wb');
        static::assertIsResource($file);
        fwrite($file(string) $fileData['content']);
        fclose($file);

        $uploadedFile = new UploadedFile($filePath$filePath$fileData['providedType']);

        $detectedType = $fileService->detectType($uploadedFile);
        static::assertSame($fileData['expectedType']$detectedType);

        unlink($filePath);
    }

    
$tempFile = tempnam(sys_get_temp_dir(), '');
        static::assertIsString($tempFile);
        copy(self::TEST_IMAGE, $tempFile);

        $fileSize = filesize($tempFile);
        static::assertIsInt($fileSize);
        $mediaFile = new MediaFile($tempFile, 'image/png', 'png', $fileSize);

        $pathName = $this->urlGenerator->getRelativeMediaUrl($png);

        $resource = fopen($tempFile, 'rb');
        static::assertIsResource($resource);
        $this->getPublicFilesystem()->writeStream($pathName$resource);

        static::assertIsString($png->getFileName());

        try {
            $this->fileSaver->persistFileToMedia(
                $mediaFile,
                $png->getFileName(),
                $png->getId(),
                $context
            );
        }
$this->assertSame('Symfony\Component\ErrorHandler\{closure}', $trace[0]['function']);
            $this->assertSame(ErrorHandler::class$trace[0]['class']);
            $this->assertSame('triggerNotice', $trace[1]['function']);
            $this->assertSame(__CLASS__, $trace[1]['class']);
        }
    }

    public function testSuccessCall()
    {
        touch($filename = tempnam(sys_get_temp_dir(), 'sf_error_handler_'));

        self::assertIsResource(ErrorHandler::call('fopen', $filename, 'r'));

        unlink($filename);
    }

    public function testConstruct()
    {
        try {
            $handler = ErrorHandler::register();
            $handler->throwAt(3, true);
            $this->assertEquals(3 | \E_RECOVERABLE_ERROR | \E_USER_ERROR, $handler->throwAt(0));
        } finally {
            
Home | Imprint | This part of the site doesn't use cookies.