tests/unit/Subjects/AbstractEavSubjectTest.php
/**
     * Test the castValueByBackendType() method.
     *
     * @param string      $backendType The backend type we want to cast to
     * @param string|null $value       The value that should be cased
     * @param mixed       $expected    The expected casting result
     *
     * @return void
     *
     * @dataProvider backendTypeProvider()
     */
Test the castValueByBackendType() method.
@param string      $backendType The backend type we want to cast to
@param string|null $value       The value that should be cased
@param mixed       $expected    The expected casting result

@return void


Test the castValueByBackendType () method . @param string $backendType The backend type we want to cast to @param string|null $value The value that should be cased @param mixed $expected The expected casting result @return void
public function testCastValueByBackendType($backendType, $value, $expected, $sourceLocale = 'en_US')
    {
        $dateConverterConfiguration = $this->getMockBuilder(DateConverterConfigurationInterface::class)
            ->setMethods(get_class_methods(DateConverterConfigurationInterface::class))
            ->getMock();
        $dateConverterConfiguration
            ->expects($this->any())
            ->method('getSourceDateFormat')
            ->willReturn('n/d/y, g:i A');
        $numberConverterConfiguration = $this->getMockBuilder(NumberConverterConfigurationInterface::class)
            ->setMethods(get_class_methods(NumberConverterConfigurationInterface::class))
            ->getMock();
        $numberConverterConfiguration
            ->expects($this->any())
            ->method('getLocale')
            ->willReturn($sourceLocale);
        $subjectConfiguration = $this->getMockBuilder(SubjectConfigurationInterface::class)
            ->setMethods(get_class_methods(SubjectConfigurationInterface::class))
            ->getMock();
        $subjectConfiguration
            ->expects($this->any())
            ->method('getNumberConverter')
            ->willReturn($numberConverterConfiguration);
        $subjectConfiguration
            ->expects($this->any())
            ->method('getDateConverter')
            ->willReturn($dateConverterConfiguration);
        $dateConverter = $this->getMockBuilder(SimpleDateConverter::class)
            ->setMethods(array('getSubjectConfiguration'))
            ->getMock();
        $dateConverter
            ->expects($this->any())
            ->method('getSubjectConfiguration')
            ->willReturn($subjectConfiguration);
        $numberConverter = $this->getMockBuilder(SimpleNumberConverter::class)
            ->setMethods(array('getSubjectConfiguration'))
            ->getMock();
        $numberConverter
            ->expects($this->any())
            ->method('getSubjectConfiguration')
            ->willReturn($subjectConfiguration);
        $this->abstractEavSubject->setDateConverter($dateConverter);
        $this->abstractEavSubject->setNumberConverter($numberConverter);
        $this->assertSame($expected, $this->abstractEavSubject->castValueByBackendType($backendType, $value));
    }
public function testCastValueByBackendType ( $ backendType , $ value , $ expected , $ sourceLocale = 'en_US' ) { $ dateConverterConfiguration = $ this -> getMockBuilder ( DateConverterConfigurationInterface :: class ) -> setMethods ( get_class_methods ( DateConverterConfigurationInterface :: class ) ) -> getMock ( ) ; $ dateConverterConfiguration -> expects ( $ this -> any ( ) ) -> method ( 'getSourceDateFormat' ) -> willReturn ( 'n/d/y, g:i A' ) ; $ numberConverterConfiguration = $ this -> getMockBuilder ( NumberConverterConfigurationInterface :: class ) -> setMethods ( get_class_methods ( NumberConverterConfigurationInterface :: class ) ) -> getMock ( ) ; $ numberConverterConfiguration -> expects ( $ this -> any ( ) ) -> method ( 'getLocale' ) -> willReturn ( $ sourceLocale ) ; $ subjectConfiguration = $ this -> getMockBuilder ( SubjectConfigurationInterface :: class ) -> setMethods ( get_class_methods ( SubjectConfigurationInterface :: class ) ) -> getMock ( ) ; $ subjectConfiguration -> expects ( $ this -> any ( ) ) -> method ( 'getNumberConverter' ) -> willReturn ( $ numberConverterConfiguration ) ; $ subjectConfiguration -> expects ( $ this -> any ( ) ) -> method ( 'getDateConverter' ) -> willReturn ( $ dateConverterConfiguration ) ; $ dateConverter = $ this -> getMockBuilder ( SimpleDateConverter :: class ) -> setMethods ( array ( 'getSubjectConfiguration' ) ) -> getMock ( ) ; $ dateConverter -> expects ( $ this -> any ( ) ) -> method ( 'getSubjectConfiguration' ) -> willReturn ( $ subjectConfiguration ) ; $ numberConverter = $ this -> getMockBuilder ( SimpleNumberConverter :: class ) -> setMethods ( array ( 'getSubjectConfiguration' ) ) -> getMock ( ) ; $ numberConverter -> expects ( $ this -> any ( ) ) -> method ( 'getSubjectConfiguration' ) -> willReturn ( $ subjectConfiguration ) ; $ this -> abstractEavSubject -> setDateConverter ( $ dateConverter ) ; $ this -> abstractEavSubject -> setNumberConverter ( $ numberConverter ) ; $ this -> assertSame ( $ expected , $ this -> abstractEavSubject -> castValueByBackendType ( $ backendType , $ value ) ) ; }
Test the castValueByBackendType() method.
Test the castValueByBackendType () method .
// initialize the date converter configuation // initialize the number converter configuation // initialize the subject configuration // initialize the date converter // initialize the number converter // set number and datetime converter instances // cast the passed values