<commit_before><?php

namespace Boomerang\Test;

use Boomerang\HttpResponseValidator;
use Boomerang\Interfaces\HttpResponseInterface;

class HttpResponseValidatorTest extends \PHPUnit_Framework_TestCase {


	public function testGetResponse() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock  = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$valid = new HttpResponseValidator($mock);
		$this->assertSame($mock, $valid->getResponse());
	}

	public function testExpectStatus() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
		->method('getStatus')
		->will($this->returnValue(200));

		$valid = new HttpResponseValidator($mock);
		$valid->expectStatus(200);
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(false, $lastExpectation->getFail());

		# ==

		$valid->expectStatus(302);
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());

	}

	public function testExpectHeader() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
		->method('getHeader')
		->will($this->returnValue('test'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectHeader('test', 'test');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectHeader('test', 'fail');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

		$mock->expects($this->any())
		->method('getHeader')
		->will($this->returnValue(false));

		$valid->expectHeader('test', false);
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectHeaderContains() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
		->method('getHeader')
		->will($this->returnValue('thisIsMyTestHeader'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectHeaderContains('test', 'IsMyTest');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectHeaderContains('test', 'fail');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

		$mock->expects($this->any())
		->method('getHeader')
		->will($this->returnValue(false));

		$valid->expectHeaderContains('test', false);
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectBody() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
		->method('getBody')
		->will($this->returnValue('test'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectBody('test');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectBody('fail');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

//		$mock->expects($this->any())
//		->method('getBody')
//		->will($this->returnValue(false));
//
//		$valid->expectBody(false);
//		$lastExpectation = end($valid->getExpectationResults());
//
//		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectBodyContains() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
		->method('getBody')
		->will($this->returnValue('thisIsMyTestHeader'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectBodyContains('IsMyTest');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectBodyContains('fail');
		$lastExpectation = end($valid->getExpectationResults());

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

//		$mock->expects($this->any())
//		->method('getBody')
//		->will($this->returnValue(false));
//
//		$valid->expectBodyContains('test', false);
//		$lastExpectation = end($valid->getExpectationResults());
//
//		$this->assertSame(true, $lastExpectation->getFail());
	}

//	public function testGetExpectationResults() {
//
//	}
}<commit_msg>Fixes test for PHP7<commit_after><?php

namespace Boomerang\Test;

use Boomerang\HttpResponseValidator;
use Boomerang\Interfaces\HttpResponseInterface;

class HttpResponseValidatorTest extends \PHPUnit_Framework_TestCase {


	public function testGetResponse() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock  = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$valid = new HttpResponseValidator($mock);
		$this->assertSame($mock, $valid->getResponse());
	}

	public function testExpectStatus() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
			->method('getStatus')
			->will($this->returnValue(200));

		$valid = new HttpResponseValidator($mock);
		$valid->expectStatus(200);
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(false, $lastExpectation->getFail());

		# ==

		$valid->expectStatus(302);
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectHeader() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
			->method('getHeader')
			->will($this->returnValue('test'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectHeader('test', 'test');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectHeader('test', 'fail');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

		$mock->expects($this->any())
			->method('getHeader')
			->will($this->returnValue(false));

		$valid->expectHeader('test', false);
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectHeaderContains() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
			->method('getHeader')
			->will($this->returnValue('thisIsMyTestHeader'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectHeaderContains('test', 'IsMyTest');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectHeaderContains('test', 'fail');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

		$mock->expects($this->any())
			->method('getHeader')
			->will($this->returnValue(false));

		$valid->expectHeaderContains('test', false);
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectBody() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
			->method('getBody')
			->will($this->returnValue('test'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectBody('test');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectBody('fail');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

		//		$mock->expects($this->any())
		//		->method('getBody')
		//		->will($this->returnValue(false));
		//
		//		$valid->expectBody(false);
		//		$lastExpectation = end($valid->getExpectationResults());
		//
		//		$this->assertSame(true, $lastExpectation->getFail());
	}

	public function testExpectBodyContains() {
		/**
		 * @var $mock HttpResponseInterface|\PHPUnit_Framework_MockObject_MockObject
		 */
		$mock = $this->getMock('Boomerang\\Interfaces\\HttpResponseInterface');
		$mock->expects($this->any())
			->method('getBody')
			->will($this->returnValue('thisIsMyTestHeader'));

		$valid = new HttpResponseValidator($mock);
		$valid->expectBodyContains('IsMyTest');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(false, $lastExpectation->getFail());

		# == Fail

		$valid->expectBodyContains('fail');
		$expResults      = $valid->getExpectationResults();
		$lastExpectation = end($expResults);

		$this->assertSame(true, $lastExpectation->getFail());

		# == False

		//		$mock->expects($this->any())
		//		->method('getBody')
		//		->will($this->returnValue(false));
		//
		//		$valid->expectBodyContains('test', false);
		//		$lastExpectation = end($valid->getExpectationResults());
		//
		//		$this->assertSame(true, $lastExpectation->getFail());
	}

	//	public function testGetExpectationResults() {
	//
	//	}
}
{'fraction_non_alphanumeric': 0.18910195557243212, 'fraction_numerical': 0.0018036833111828366, 'mean_word_length': 5.197058823529412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 221, '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': '6335820', 'n_tokens_mistral': 3598, 'n_tokens_neox': 3258, 'n_words': 415}