<?php

namespace Tests\FileNamingResolver;

use FileNamingResolver\FileInfo;
use FileNamingResolver\FileNamingResolver;
use FileNamingResolver\NamingStrategy\DatetimeNamingStrategy;
use FileNamingResolver\NamingStrategy\HashNamingStrategy;

/**
 * @author Victor Bocharsky <bocharsky.bw@gmail.com>
 */
class FileNamingResolverTest extends \PHPUnit_Framework_TestCase
{
    public function testSetGetNamingStrategy()
    {
        $hashStrategy = new HashNamingStrategy();
        $datetimeStrategy = new DatetimeNamingStrategy();

        $resolver = new FileNamingResolver($hashStrategy);
        $this->assertSame($hashStrategy, $resolver->getNamingStrategy());

        $resolver->setNamingStrategy($datetimeStrategy);
        $this->assertSame($datetimeStrategy, $resolver->getNamingStrategy());
    }

    public function testResolveName()
    {
        $fileInfo = new FileInfo(__FILE__);
        $hashStrategy = new HashNamingStrategy();
        $resolver = new FileNamingResolver($hashStrategy);
        $filename = $resolver->resolveName($fileInfo);

        $this->assertInternalType('string', $filename);
        $this->assertStringStartsWith($fileInfo->getPath(), $filename);
        $this->assertStringEndsWith($fileInfo->getExtension(), $filename);
    }
}

<?php

namespace Tests\FileNamingResolver;

use FileNamingResolver\FileInfo;
use FileNamingResolver\FileNamingResolver;
use FileNamingResolver\NamingStrategy\NamingStrategyInterface;

/**
 * @author Victor Bocharsky <bocharsky.bw@gmail.com>
 */
class FileNamingResolverTest extends \PHPUnit_Framework_TestCase
{
    public function testSetGetNamingStrategy()
    {
        $mockedStrategy = $this->createMockedStrategy();
        $resolver = new FileNamingResolver($mockedStrategy);
        $this->assertSame($mockedStrategy, $resolver->getNamingStrategy());

        $anotherMockedStrategy = $this->createMockedStrategy();
        $resolver->setNamingStrategy($anotherMockedStrategy);
        $this->assertSame($anotherMockedStrategy, $resolver->getNamingStrategy());
    }

    public function testResolveName()
    {
        $mockedFileInfo = $this->createMockedFileInfo();
        $mockedStrategy = $this->createMockedStrategy();
        $mockedStrategy
            ->expects($this->once())
            ->method('provideName')
            ->with($mockedFileInfo)
            ->willReturn(__FILE__)
        ;
        $resolver = new FileNamingResolver($mockedStrategy);
        $pathname = $resolver->resolveName($mockedFileInfo);

        $this->assertInternalType('string', $pathname);
    }

    /**
     * @return \PHPUnit_Framework_MockObject_MockObject|NamingStrategyInterface
     */
    private function createMockedStrategy()
    {
        return $this
            ->getMockBuilder('FileNamingResolver\NamingStrategy\NamingStrategyInterface')
            ->getMock()
        ;
    }

    /**
     * @return \PHPUnit_Framework_MockObject_MockObject|FileInfo
     */
    private function createMockedFileInfo()
    {
        return $this
            ->getMockBuilder('FileNamingResolver\FileInfo')
            ->setConstructorArgs(array(__FILE__))
            ->getMock()
        ;
    }
}

Use mocked objects in tests
Use mocked objects in tests
