tests/unit/Plugins/SubjectPluginTest.php
/**
     * Tests's the plugin's process method with a subject.
     *
     * @return void
     */
Tests's the plugin's process method with a subject.
@return void
Tests ' s the plugin ' s process method with a subject . @return void
public function testProcessWithOneSubject()
    {
        $mockSubjectConfiguration = $this->getMockBuilder(SubjectConfigurationInterface::class)->getMock();
        $mockSubjectConfigurations = array($mockSubjectConfiguration);
         factory
        $this->mockSubjectExecutor->expects($this->once())
            ->method('execute')
            ->willReturn(null);
        $mockFileResolver = $this->getMockBuilder(FileResolverInterface::class)->getMock();
        $mockFileResolver->expects($this->once())
            ->method('loadFiles')
            ->willReturn(array(__DIR__ . DIRECTORY_SEPARATOR . '_file' . DIRECTORY_SEPARATOR . 'product-import_20170720-125052_01.csv'));
        $mockFileResolver->expects($this->once())
            ->method('getMatches')
            ->willReturn(array(array()));
        $mockFileResolver->expects($this->once())
            ->method('reset');
        $this->mockFileResolverFactory->expects($this->once())
            ->method('createFileResolver')
            ->willReturn($mockFileResolver);
        $mockRegistryProcessor = $this->getMockBuilder('TechDivision\Import\Services\RegistryProcessorInterface')
            ->setMethods(get_class_methods('TechDivision\Import\Services\RegistryProcessorInterface'))
            ->getMock();
        $mockRegistryProcessor->expects($this->exactly(2))
            ->method('mergeAttributesRecursive')
            ->willReturn(null);
        $mockSystemLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')
            ->setMethods(get_class_methods('Psr\Log\LoggerInterface'))
            ->getMock();
        $this->mockApplication->expects($this->exactly(2))
            ->method('getRegistryProcessor')
            ->willReturn($mockRegistryProcessor);
        $this->mockApplication->expects($this->any())
            ->method('getSerial')
            ->willReturn(uniqid());
        $this->mockApplication->expects($this->any())
            ->method('getSystemLogger')
            ->willReturn($mockSystemLogger);
        $mockPluginConfiguration = $this->getMockBuilder('TechDivision\Import\Configuration\PluginConfigurationInterface')
                                        ->setMethods(get_class_methods('TechDivision\Import\Configuration\PluginConfigurationInterface'))
                                        ->getMock();
        $mockPluginConfiguration->expects($this->once())
                                ->method('getSubjects')
                                ->willReturn($mockSubjectConfigurations);
        $this->subject->setPluginConfiguration($mockPluginConfiguration);
        $this->subject->process();
    }
public function testProcessWithOneSubject ( ) { $ mockSubjectConfiguration = $ this -> getMockBuilder ( SubjectConfigurationInterface :: class ) -> getMock ( ) ; $ mockSubjectConfigurations = array ( $ mockSubjectConfiguration ) ; $ this -> mockSubjectExecutor -> expects ( $ this -> once ( ) ) -> method ( 'execute' ) -> willReturn ( null ) ; $ mockFileResolver = $ this -> getMockBuilder ( FileResolverInterface :: class ) -> getMock ( ) ; $ mockFileResolver -> expects ( $ this -> once ( ) ) -> method ( 'loadFiles' ) -> willReturn ( array ( __DIR__ . DIRECTORY_SEPARATOR . '_file' . DIRECTORY_SEPARATOR . 'product-import_20170720-125052_01.csv' ) ) ; $ mockFileResolver -> expects ( $ this -> once ( ) ) -> method ( 'getMatches' ) -> willReturn ( array ( array ( ) ) ) ; $ mockFileResolver -> expects ( $ this -> once ( ) ) -> method ( 'reset' ) ; $ this -> mockFileResolverFactory -> expects ( $ this -> once ( ) ) -> method ( 'createFileResolver' ) -> willReturn ( $ mockFileResolver ) ; $ mockRegistryProcessor = $ this -> getMockBuilder ( 'TechDivision\Import\Services\RegistryProcessorInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Services\RegistryProcessorInterface' ) ) -> getMock ( ) ; $ mockRegistryProcessor -> expects ( $ this -> exactly ( 2 ) ) -> method ( 'mergeAttributesRecursive' ) -> willReturn ( null ) ; $ mockSystemLogger = $ this -> getMockBuilder ( 'Psr\Log\LoggerInterface' ) -> setMethods ( get_class_methods ( 'Psr\Log\LoggerInterface' ) ) -> getMock ( ) ; $ this -> mockApplication -> expects ( $ this -> exactly ( 2 ) ) -> method ( 'getRegistryProcessor' ) -> willReturn ( $ mockRegistryProcessor ) ; $ this -> mockApplication -> expects ( $ this -> any ( ) ) -> method ( 'getSerial' ) -> willReturn ( uniqid ( ) ) ; $ this -> mockApplication -> expects ( $ this -> any ( ) ) -> method ( 'getSystemLogger' ) -> willReturn ( $ mockSystemLogger ) ; $ mockPluginConfiguration = $ this -> getMockBuilder ( 'TechDivision\Import\Configuration\PluginConfigurationInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Configuration\PluginConfigurationInterface' ) ) -> getMock ( ) ; $ mockPluginConfiguration -> expects ( $ this -> once ( ) ) -> method ( 'getSubjects' ) -> willReturn ( $ mockSubjectConfigurations ) ; $ this -> subject -> setPluginConfiguration ( $ mockPluginConfiguration ) ; $ this -> subject -> process ( ) ; }
Tests's the plugin's process method with a subject.
Tests ' s the plugin ' s process method with a subject .
// mock the subject // mock the array with subjects // mock the subject factory // initialize the mock file resolver instance // mock the file resolver methods // let the mock file resolver factory create a mock file resolver instance // mock the registry processor // mock the system logger // mock the application methods // create a mock plugin configuration // set the plugin configuration // invoke the process() method