compilationDataReaderMock = $this->createMock(CompilationDataService::class); $this->compilationDataReaderMock->method('readCompilationData') ->willReturn($this->createMock(QtiComponent::class)); $this->compilationDataWriterMock = $this->createMock(CompilationDataService::class); $this->compilationDataWriterMock->method('readCompilationData') ->willReturn($this->createMock(QtiComponent::class)); $this->directoryMock = $this->createMock(tao_models_classes_service_StorageDirectory::class); $this->fileMock = $this->createMock(File::class); $this->fileMock->method('getBasename') ->willReturn(self::FILE_BASE_NAME); $this->object = new CompiledTestConverterService($this->compilationDataReaderMock, $this->compilationDataWriterMock); } public function testConvertFileExists() { $expectedNewFileType = 'NEW_EXT'; $expectedNewFile = $this->createMock(File::class); $expectedNewFile->method('exists') ->willReturn(true); $expectedNewFile->expects($this->once()) ->method('delete'); $this->compilationDataWriterMock->method('getOutputFileType') ->willReturn($expectedNewFileType); $this->directoryMock->method('getFile') ->with("BASE_NAME.{$expectedNewFileType}") ->willReturn($expectedNewFile); $result = $this->object->convert($this->fileMock, $this->directoryMock); $this->assertSame($expectedNewFile, $result, 'Method must return test file converted to PHP.'); } public function testConvertFileDontExist() { $expectedNewFileType = 'NEW_EXT'; $expectedPhpFile = $this->createMock(File::class); $expectedPhpFile->method('exists') ->willReturn(false); $expectedPhpFile->expects($this->never()) ->method('delete'); $this->compilationDataWriterMock->method('getOutputFileType') ->willReturn($expectedNewFileType); $this->directoryMock->method('getFile') ->with("BASE_NAME.{$expectedNewFileType}") ->willReturn($expectedPhpFile); $result = $this->object->convert($this->fileMock, $this->directoryMock); $this->assertSame($expectedPhpFile, $result, 'Method must return test file converted to PHP.'); } }