<commit_before><?php

use Mockery as m;
use Illuminate\View\Compilers\BladeCompiler;

class ViewBladeCompilerTest extends PHPUnit_Framework_TestCase {

	public function tearDown()
	{
		m::close();
	}


	public function testIsExpiredReturnsTrueIfCompiledFileDoesntExist()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
		$files->shouldReceive('exists')->once()->with(__DIR__.'/'.md5('foo'))->andReturn(false);
		$this->assertTrue($compiler->isExpired('foo'));
	}


	public function testIsExpiredReturnsTrueIfCachePathIsNull()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), null);
		$files->shouldReceive('exists')->never();
		$this->assertTrue($compiler->isExpired('foo'));
	}


	public function testIsExpiredReturnsTrueWhenModificationTimesWarrant()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
		$files->shouldReceive('exists')->once()->with(__DIR__.'/'.md5('foo'))->andReturn(true);
		$files->shouldReceive('lastModified')->once()->with('foo')->andReturn(100);
		$files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.md5('foo'))->andReturn(0);
		$this->assertTrue($compiler->isExpired('foo'));
	}


	public function testCompilePathIsProperlyCreated()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals(__DIR__.'/'.md5('foo'), $compiler->getCompiledPath('foo'));
	}


	public function testCompileCompilesFileAndReturnsContents()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
		$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
		$files->shouldReceive('put')->once()->with(__DIR__.'/'.md5('foo'), 'Hello World');
		$compiler->compile('foo');
	}


	public function testCompileDoesntStoreFilesWhenCachePathIsNull()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), null);
		$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
		$files->shouldReceive('put')->never();
		$compiler->compile('foo');
	}


	public function testEchosAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('<?php echo e($name); ?>', $compiler->compileString('{{{$name}}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{$name}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{ $name }}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{ 
			$name
		}}'));
	}


	public function testEscapedWithAtEchosAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('{{$name}}', $compiler->compileString('@{{$name}}'));
		$this->assertEquals('{{ $name }}', $compiler->compileString('@{{ $name }}'));
		$this->assertEquals('{{
			$name
		}}', 
		$compiler->compileString('@{{
			$name
		}}'));
	}


	public function testReversedEchosAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$compiler->setEscapedContentTags('{{', '}}');
		$compiler->setContentTags('{{{', '}}}');
		$this->assertEquals('<?php echo e($name); ?>', $compiler->compileString('{{$name}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{{$name}}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{{ $name }}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{{ 
			$name
		}}}'));
	}

	public function testExtendsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@extends(\'foo\')
test';
		$expected = "test\r\n".'<?php echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';
		$this->assertEquals($expected, $compiler->compileString($string));


		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@extends(name(foo))
test';
		$expected = "test\r\n".'<?php echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testCommentsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '{{--this is a comment--}}';
		$expected = '<?php /* this is a comment */ ?>';
		$this->assertEquals($expected, $compiler->compileString($string));


		$string = '{{--
this is a comment
--}}';
		$expected = '<?php /* 
this is a comment
 */ ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testIfStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@if (name(foo(bar)))
breeze
@endif';
		$expected = '<?php if (name(foo(bar))): ?>
breeze
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testElseStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@if (name(foo(bar)))
breeze
@else
boom
@endif';
		$expected = '<?php if (name(foo(bar))): ?>
breeze
<?php else: ?>
boom
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testElseIfStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@if (name(foo(bar)))
breeze
@elseif (boom(breeze))
boom
@endif';
		$expected = '<?php if (name(foo(bar))): ?>
breeze
<?php elseif (boom(breeze)): ?>
boom
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testUnlessStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@unless (name(foo(bar)))
breeze
@endunless';
		$expected = '<?php if ( ! (name(foo(bar)))): ?>
breeze
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testIncludesAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('<?php echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@include(\'foo\')'));
		$this->assertEquals('<?php echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@include(name(foo))'));
	}


	public function testShowEachAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('<?php echo $__env->renderEach(\'foo\', \'bar\'); ?>', $compiler->compileString('@each(\'foo\', \'bar\')'));
		$this->assertEquals('<?php echo $__env->renderEach(name(foo)); ?>', $compiler->compileString('@each(name(foo))'));
	}


	public function testYieldsAreCompiled()<commit_msg>Added test data to Blade Compiler Test<commit_after><?php

use Mockery as m;
use Illuminate\View\Compilers\BladeCompiler;

class ViewBladeCompilerTest extends PHPUnit_Framework_TestCase {

	public function tearDown()
	{
		m::close();
	}


	public function testIsExpiredReturnsTrueIfCompiledFileDoesntExist()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
		$files->shouldReceive('exists')->once()->with(__DIR__.'/'.md5('foo'))->andReturn(false);
		$this->assertTrue($compiler->isExpired('foo'));
	}


	public function testIsExpiredReturnsTrueIfCachePathIsNull()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), null);
		$files->shouldReceive('exists')->never();
		$this->assertTrue($compiler->isExpired('foo'));
	}


	public function testIsExpiredReturnsTrueWhenModificationTimesWarrant()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
		$files->shouldReceive('exists')->once()->with(__DIR__.'/'.md5('foo'))->andReturn(true);
		$files->shouldReceive('lastModified')->once()->with('foo')->andReturn(100);
		$files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.md5('foo'))->andReturn(0);
		$this->assertTrue($compiler->isExpired('foo'));
	}


	public function testCompilePathIsProperlyCreated()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals(__DIR__.'/'.md5('foo'), $compiler->getCompiledPath('foo'));
	}


	public function testCompileCompilesFileAndReturnsContents()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
		$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
		$files->shouldReceive('put')->once()->with(__DIR__.'/'.md5('foo'), 'Hello World');
		$compiler->compile('foo');
	}


	public function testCompileDoesntStoreFilesWhenCachePathIsNull()
	{
		$compiler = new BladeCompiler($files = $this->getFiles(), null);
		$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
		$files->shouldReceive('put')->never();
		$compiler->compile('foo');
	}


	public function testEchosAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('<?php echo e($name); ?>', $compiler->compileString('{{{$name}}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{$name}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{ $name }}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{ 
			$name
		}}'));
	}


	public function testEscapedWithAtEchosAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('{{$name}}', $compiler->compileString('@{{$name}}'));
		$this->assertEquals('{{ $name }}', $compiler->compileString('@{{ $name }}'));
		$this->assertEquals('{{
			$name
		}}', 
		$compiler->compileString('@{{
			$name
		}}'));
	}


	public function testReversedEchosAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$compiler->setEscapedContentTags('{{', '}}');
		$compiler->setContentTags('{{{', '}}}');
		$this->assertEquals('<?php echo e($name); ?>', $compiler->compileString('{{$name}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{{$name}}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{{ $name }}}'));
		$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{{ 
			$name
		}}}'));
	}

	public function testExtendsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@extends(\'foo\')
test';
		$expected = "test\r\n".'<?php echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';
		$this->assertEquals($expected, $compiler->compileString($string));


		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@extends(name(foo))
test';
		$expected = "test\r\n".'<?php echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testCommentsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '{{--this is a comment--}}';
		$expected = '<?php /* this is a comment */ ?>';
		$this->assertEquals($expected, $compiler->compileString($string));


		$string = '{{--
this is a comment
--}}';
		$expected = '<?php /* 
this is a comment
 */ ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testIfStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@if (name(foo(bar)))
breeze
@endif';
		$expected = '<?php if (name(foo(bar))): ?>
breeze
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testElseStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@if (name(foo(bar)))
breeze
@else
boom
@endif';
		$expected = '<?php if (name(foo(bar))): ?>
breeze
<?php else: ?>
boom
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testElseIfStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@if (name(foo(bar)))
breeze
@elseif (boom(breeze))
boom
@endif';
		$expected = '<?php if (name(foo(bar))): ?>
breeze
<?php elseif (boom(breeze)): ?>
boom
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}


	public function testUnlessStatementsAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = '@unless (name(foo(bar)))
breeze
@endunless';
		$expected = '<?php if ( ! (name(foo(bar)))): ?>
breeze
<?php endif; ?>';
		$this->assertEquals($expected, $compiler->compileString($string));
	}
	
	
	public function testStatementThatContainsNonConsecutiveParanthesisAreCompiled() 
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$string = "Foo @lang(function_call('foo(blah)')) bar";
		$expected = "Foo <?php echo \Illuminate\Support\Facades\Lang::get(function_call('foo(blah)')); ?> bar";
		$this->assertEquals($expected, $compiler->compileString($string));
	}
	

	public function testIncludesAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('<?php echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@include(\'foo\')'));
		$this->assertEquals('<?php echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@include(name(foo))'));
	}


	public function testShowEachAreCompiled()
	{
		$compiler = new BladeCompiler($this->getFiles(), __DIR__);
		$this->assertEquals('<?php echo $__env->renderEach(\'foo\', \'bar\'); ?>', $compiler->compileString('@each(\'foo\', \'bar\')'));
		$this->assertEquals('<?php echo $__env->renderEach(name(foo)); ?>', $compiler->compileString('@each(name(foo))'));
	}


	public function testYieldsAreCompiled()
{'fraction_non_alphanumeric': 0.2274129888769286, 'fraction_numerical': 0.0012917115177610333, 'mean_word_length': 6.243243243243243, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 293, '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': '5756176', 'n_tokens_mistral': 4818, 'n_tokens_neox': 4528, 'n_words': 736}