<commit_before><?php
/*
 * This file is part of the Onema {test} Package.
 * For the full copyright and license information, 
 * please view the LICENSE file that was distributed 
 * with this source code.
 */
namespace Onema\Test;

use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Onema\ClassyFile\ClassyFile;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * ClassyFileTest - Description. 
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2015, Onema
 * @group classyfile
 */
class ClassyFileTest extends \PHPUnit_Framework_TestCase
{
    public function testClassToFileConversionStyle1()
    {
        $classyfile = new ClassyFile();
        $dispatcher = new EventDispatcher();
        $classyfile->setEventDispatcher($dispatcher);

        $codeLocation = __DIR__.'/mock/';
        $codeDestination = '/tmp/';
        $classyfile->generateClassFiles($codeDestination, $codeLocation);

        $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/Scale.php', 'File was not created in the right location.');
        $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/ServiceSettings.php', 'File was not created in the right location.');
        $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/TimeInterval.php', 'File was not created in the right location.');
        $this->assertEquals($dispatcher, $classyfile->getEventDispatcher());

        // Delete all files/
        $filesystem = new Filesystem(new Local($codeDestination));
        $filesystem->deleteDir('/Service/');
    }

    public function testClassToFileConversionMocked()
    {
        $mockAdapter = $this->getMockBuilder('\League\Flysystem\Adapter\Local')
            ->disableOriginalConstructor()
            ->setMethods(['has', 'createDir', 'write'])
            ->getMock();

        // plugin calls this method 3 times, internally write calls this method each time checking if
        // the file exist. write has must always return false otherwise it will throw an exception.
        $mockAdapter->expects($this->exactly(6))
            ->method('has')
            ->will($this->onConsecutiveCalls(false, false, true, false, true, false));

        $mockAdapter->expects($this->once())
            ->method('createDir')
            ->willReturn(true);

        $mockAdapter->expects($this->exactly(3))
            ->method('write')
            ->willReturn(true);

        $classyfile = new ClassyFile();
        $classyfile->setFilesystemAdapter($mockAdapter);
        $dispatcher = new EventDispatcher();
        $classyfile->setEventDispatcher($dispatcher);

        $codeLocation = __DIR__.'/mock/';
        $codeDestination = '/tmp/';
        $classyfile->generateClassFiles($codeDestination, $codeLocation);
    }

    public function testClassToFileConversionStyle2()
    {
        $classyfile = new ClassyFile();

        $dispatcher = new EventDispatcher();
        $classyfile->setEventDispatcher($dispatcher);

        $codeLocation = __DIR__.'/mock/src/VendorName/ProjectName/Category/ProductName/v123456/';
        $codeDestination = '/tmp/';
        $classyfile->generateClassFiles($codeDestination, $codeLocation, true, 6, 4);

        $this->assertFileExists('/tmp/Vendor/Api/Category/ProductName/Date.php');
        $this->assertFileExists('/tmp/Vendor/Api/Category/ProductName/DateRange.php');
        $this->assertFileExists('/tmp/Vendor/Api/Category/ProductName/OrderBy.php');
<commit_msg>Update path to class style 2 to avoid issues with gitignore (vendor was in path.)<commit_after><?php
/*
 * This file is part of the Onema {test} Package.
 * For the full copyright and license information, 
 * please view the LICENSE file that was distributed 
 * with this source code.
 */
namespace Onema\Test;

use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Onema\ClassyFile\ClassyFile;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * ClassyFileTest - Description. 
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2015, Onema
 * @group classyfile
 */
class ClassyFileTest extends \PHPUnit_Framework_TestCase
{
    public function testClassToFileConversionStyle1()
    {
        $classyfile = new ClassyFile();
        $dispatcher = new EventDispatcher();
        $classyfile->setEventDispatcher($dispatcher);

        $codeLocation = __DIR__.'/mock/';
        $codeDestination = '/tmp/';
        $classyfile->generateClassFiles($codeDestination, $codeLocation);

        $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/Scale.php', 'File was not created in the right location.');
        $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/ServiceSettings.php', 'File was not created in the right location.');
        $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/TimeInterval.php', 'File was not created in the right location.');
        $this->assertEquals($dispatcher, $classyfile->getEventDispatcher());

        // Delete all files/
        $filesystem = new Filesystem(new Local($codeDestination));
        $filesystem->deleteDir('/Service/');
    }

    public function testClassToFileConversionMocked()
    {
        $mockAdapter = $this->getMockBuilder('\League\Flysystem\Adapter\Local')
            ->disableOriginalConstructor()
            ->setMethods(['has', 'createDir', 'write'])
            ->getMock();

        // plugin calls this method 3 times, internally write calls this method each time checking if
        // the file exist. write has must always return false otherwise it will throw an exception.
        $mockAdapter->expects($this->exactly(6))
            ->method('has')
            ->will($this->onConsecutiveCalls(false, false, true, false, true, false));

        $mockAdapter->expects($this->once())
            ->method('createDir')
            ->willReturn(true);

        $mockAdapter->expects($this->exactly(3))
            ->method('write')
            ->willReturn(true);

        $classyfile = new ClassyFile();
        $classyfile->setFilesystemAdapter($mockAdapter);
        $dispatcher = new EventDispatcher();
        $classyfile->setEventDispatcher($dispatcher);

        $codeLocation = __DIR__.'/mock/';
        $codeDestination = '/tmp/';
        $classyfile->generateClassFiles($codeDestination, $codeLocation);
    }

    public function testClassToFileConversionStyle2()
    {
        $classyfile = new ClassyFile();

        $dispatcher = new EventDispatcher();
        $classyfile->setEventDispatcher($dispatcher);

        $codeLocation = __DIR__.'/mock/src/VendorName/ProjectName/Category/ProductName/v123456/';
        $codeDestination = '/tmp/';
        $classyfile->generateClassFiles($codeDestination, $codeLocation, true, 6, 4);

        $this->assertFileExists('/tmp/VendorName/ProjectName/Category/ProductName/Date.php');
        $this->assertFileExists('/tmp/VendorName/ProjectName/Category/ProductName/DateRange.php');
        $this->assertFileExists('/tmp/VendorName/ProjectName/Category/ProductName/OrderBy.php');

{'fraction_non_alphanumeric': 0.13168430082928223, 'fraction_numerical': 0.0050042893909064915, 'mean_word_length': 3.254866180048662, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2233034', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1905, 'n_words': 408}