<commit_before><?php

namespace alsvanzelf\jsonapiTests;

use alsvanzelf\jsonapi\objects\ProfileLinkObject;
use alsvanzelf\jsonapiTests\TestableNonAbstractDocument as Document;
use alsvanzelf\jsonapiTests\profiles\TestProfile;
use PHPUnit\Framework\TestCase;

/**
 * @group SeparateProcess
 */
class SeparateProcessTest extends TestCase {
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_HappyPath() {
		$document = new Document();
		
		ob_start();
		$document->sendResponse();
		$output = ob_get_clean();
		
		$this->assertSame('{"jsonapi":{"version":"1.1"}}', $output);
	}
	
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_NoContent() {
		$document = new Document();
		$document->setHttpStatusCode(204);
		
		ob_start();
		$document->sendResponse();
		$output = ob_get_clean();
		
		$this->assertSame('', $output);
		$this->assertSame(204, http_response_code());
	}
	
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_ContentTypeHeader() {
		$document = new Document();
		
		ob_start();
		$document->sendResponse();
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
		
		$options = ['contentType' => Document::CONTENT_TYPE_OFFICIAL];
		ob_start();
		$document->sendResponse($options);
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
		
		$options = ['contentType' => Document::CONTENT_TYPE_DEBUG];
		ob_start();
		$document->sendResponse($options);
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_DEBUG], \xdebug_get_headers());
		
		$options = ['contentType' => Document::CONTENT_TYPE_JSONP];
		ob_start();
		$document->sendResponse($options);
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_JSONP], \xdebug_get_headers());
	}
	
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_ContentTypeHeaderWithProfiles() {
		$profile = new TestProfile();
		$profile->setAliasedLink('https://jsonapi.org');
		
		$document = new Document();
		$document->applyProfile($profile);
		
		ob_start();
		$document->sendResponse();
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL.';profile="https://jsonapi.org", '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
		
		$profile = new TestProfile();
		$profile->setAliasedLink('https://jsonapi.org/2');
		$document->applyProfile($profile);
		
		ob_start();
		$document->sendResponse();
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL.';profile="https://jsonapi.org https://jsonapi.org/2", '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
	}
	<commit_msg>skip some tests if xdebug isn't configured<commit_after><?php

namespace alsvanzelf\jsonapiTests;

use alsvanzelf\jsonapi\objects\ProfileLinkObject;
use alsvanzelf\jsonapiTests\TestableNonAbstractDocument as Document;
use alsvanzelf\jsonapiTests\profiles\TestProfile;
use PHPUnit\Framework\TestCase;

/**
 * @group SeparateProcess
 */
class SeparateProcessTest extends TestCase {
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_HappyPath() {
		$document = new Document();
		
		ob_start();
		$document->sendResponse();
		$output = ob_get_clean();
		
		$this->assertSame('{"jsonapi":{"version":"1.1"}}', $output);
	}
	
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_NoContent() {
		$document = new Document();
		$document->setHttpStatusCode(204);
		
		ob_start();
		$document->sendResponse();
		$output = ob_get_clean();
		
		$this->assertSame('', $output);
		$this->assertSame(204, http_response_code());
	}
	
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_ContentTypeHeader() {
		if (function_exists('xdebug_get_headers') === false) {
			$this->markTestSkipped('can not run without xdebug');
		}
		
		$document = new Document();
		
		ob_start();
		$document->sendResponse();
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
		
		$options = ['contentType' => Document::CONTENT_TYPE_OFFICIAL];
		ob_start();
		$document->sendResponse($options);
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
		
		$options = ['contentType' => Document::CONTENT_TYPE_DEBUG];
		ob_start();
		$document->sendResponse($options);
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_DEBUG], \xdebug_get_headers());
		
		$options = ['contentType' => Document::CONTENT_TYPE_JSONP];
		ob_start();
		$document->sendResponse($options);
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_JSONP], \xdebug_get_headers());
	}
	
	/**
	 * @runInSeparateProcess
	 */
	public function testSendResponse_ContentTypeHeaderWithProfiles() {
		if (function_exists('xdebug_get_headers') === false) {
			$this->markTestSkipped('can not run without xdebug');
		}
		
		$profile = new TestProfile();
		$profile->setAliasedLink('https://jsonapi.org');
		
		$document = new Document();
		$document->applyProfile($profile);
		
		ob_start();
		$document->sendResponse();
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL.';profile="https://jsonapi.org", '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
		
		$profile = new TestProfile();
		$profile->setAliasedLink('https://jsonapi.org/2');
		$document->applyProfile($profile);
		
		ob_start();
		$document->sendResponse();
		ob_end_clean();
		$this->assertSame(['Content-Type: '.Document::CONTENT_TYPE_OFFICIAL.';profile="https://jsonapi.org https://jsonapi.org/2", '.Document::CONTENT_TYPE_OFFICIAL], \xdebug_get_headers());
	}
	
{'fraction_non_alphanumeric': 0.1707232867253582, 'fraction_numerical': 0.0034524426031417228, 'mean_word_length': 5.6368843069874, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 10, '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': '3602304', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1851, 'n_words': 262}