<commit_before><?php

namespace alsvanzelf\jsonapiTests;

use alsvanzelf\jsonapi\exceptions\InputException;
use alsvanzelf\jsonapiTests\helpers\TestableNonTraitExtensionMemberManager as ExtensionMemberManager;
use alsvanzelf\jsonapiTests\extensions\TestExtension;
use PHPUnit\Framework\TestCase;

class ExtensionMemberManagerTest extends TestCase {
	protected $extension;
	
	protected function setUp() {
		$this->extension = new TestExtension();
		$this->extension->setNamespace('test');
		$this->extension->setOfficialLink('https://example.org');
	}
	
	public function testAddExtensionMember_HappyPath() {
		$helper = new ExtensionMemberManager();
		
		$this->assertFalse($helper->hasExtensionMembers());
		$this->assertSame([], $helper->getExtensionMembers());
		
		$helper->addExtensionMember($this->extension, 'foo', 'bar');
		
		$array = $helper->getExtensionMembers();
		
		$this->assertTrue($helper->hasExtensionMembers());
		$this->assertCount(1, $array);
		$this->assertArrayHasKey('test:foo', $array);
		$this->assertSame('bar', $array['test:foo']);
	}
	
	public function testAddExtensionMember_WithNamespacePrefixed() {
		$helper = new ExtensionMemberManager();
		
		$helper->addExtensionMember($this->extension, 'test:foo', 'bar');
		
		$array = $helper->getExtensionMembers();
		
		$this->assertArrayHasKey('test:foo', $array);
	}
	
	public function testAddExtensionMember_WithObjectValue() {
		$helper = new ExtensionMemberManager();
		
		$object = new \stdClass();
		$object->bar = 'baz';
		
		$helper->addExtensionMember($this->extension, 'foo', $object);
		
		$array = $helper->getExtensionMembers();
		
		$this->assertArrayHasKey('test:foo', $array);
		$this->assertArrayHasKey('bar', $array['test:foo']);
		$this->assertSame('baz', $array['test:foo']['bar']);
	}
	
	public function testAddExtensionMember_InvalidNamespaceOrCharacter() {
		$helper = new ExtensionMemberManager();
		
		$this->expectException(InputException::class);
		
		$helper->addExtensionMember($this->extension, 'foo:bar', 'baz');
	}
}<commit_msg>prevent using setUp as it has a BC break between php7.1 and 7.2<commit_after><?php

namespace alsvanzelf\jsonapiTests;

use alsvanzelf\jsonapi\exceptions\InputException;
use alsvanzelf\jsonapiTests\helpers\TestableNonTraitExtensionMemberManager as ExtensionMemberManager;
use alsvanzelf\jsonapiTests\extensions\TestExtension;
use PHPUnit\Framework\TestCase;

class ExtensionMemberManagerTest extends TestCase {
	public function testAddExtensionMember_HappyPath() {
		$helper    = new ExtensionMemberManager();
		$extension = new TestExtension();
		$extension->setNamespace('test');
		
		$this->assertFalse($helper->hasExtensionMembers());
		$this->assertSame([], $helper->getExtensionMembers());
		
		$helper->addExtensionMember($extension, 'foo', 'bar');
		
		$array = $helper->getExtensionMembers();
		
		$this->assertTrue($helper->hasExtensionMembers());
		$this->assertCount(1, $array);
		$this->assertArrayHasKey('test:foo', $array);
		$this->assertSame('bar', $array['test:foo']);
	}
	
	public function testAddExtensionMember_WithNamespacePrefixed() {
		$helper    = new ExtensionMemberManager();
		$extension = new TestExtension();
		$extension->setNamespace('test');
		
		$helper->addExtensionMember($extension, 'test:foo', 'bar');
		
		$array = $helper->getExtensionMembers();
		
		$this->assertArrayHasKey('test:foo', $array);
	}
	
	public function testAddExtensionMember_WithObjectValue() {
		$helper    = new ExtensionMemberManager();
		$extension = new TestExtension();
		$extension->setNamespace('test');
		
		$object = new \stdClass();
		$object->bar = 'baz';
		
		$helper->addExtensionMember($extension, 'foo', $object);
		
		$array = $helper->getExtensionMembers();
		
		$this->assertArrayHasKey('test:foo', $array);
		$this->assertArrayHasKey('bar', $array['test:foo']);
		$this->assertSame('baz', $array['test:foo']['bar']);
	}
	
	public function testAddExtensionMember_InvalidNamespaceOrCharacter() {
		$helper    = new ExtensionMemberManager();
		$extension = new TestExtension();
		$extension->setNamespace('test');
		
		$this->expectException(InputException::class);
		
		$helper->addExtensionMember($extension, 'foo:bar', 'baz');
	}
}
{'fraction_non_alphanumeric': 0.15903671912255604, 'fraction_numerical': 0.001430615164520744, 'mean_word_length': 6.170940170940171, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 60, 'https://': 1, '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': '6637223', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1196, 'n_words': 204}