/**
  * @covers ::lookupMethodFor
  */
 public function testReturnsFallbackWhenNothingMatches()
 {
     // ----------------------------------------------------------------
     // setup your test
     $data = "hello";
     $map = [];
     $expectedResult = "nothingMatchesTheInputType";
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = InvokeMethod::onClass(LookupMethodByType_TestObject::class, 'lookupMethodFor', [$data, $map]);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @covers ::getCacheKey
  */
 public function testUsesClassNameForObjectKeyIntoStaticCache()
 {
     // ----------------------------------------------------------------
     // setup your test
     $data = new stdClass();
     $expectedResult = get_class($data);
     // ----------------------------------------------------------------
     // perform the change
     // ----------------------------------------------------------------
     // test the results
     $actualResult = InvokeMethod::onClass(IsTraversable::class, 'getCacheKey', [$data]);
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @covers ::fromObject
  * @covers ::setObjectInCache
  * @covers ::getObjectCacheName
  */
 public function testWritesToInternalCacheForObjects()
 {
     // ----------------------------------------------------------------
     // setup your test
     $obj = new AllMatchingTypesList();
     // our setup() method guarantees that we start with an empty cache
     $this->assertTrue(empty(InvokeMethod::onObject($obj, 'getCache')));
     // ----------------------------------------------------------------
     // perform the change
     $result = $obj($obj);
     // ----------------------------------------------------------------
     // test the results
     $cache = InvokeMethod::onObject($obj, 'getCache');
     $this->assertFalse(empty($cache));
     $this->assertEquals([get_class($obj) . '::object' => $result], $cache);
 }
 /**
  * @covers ::splitPathInTwo
  */
 public function testInternallySplitsAPathIntoParentAndChild()
 {
     // ----------------------------------------------------------------
     // setup your test
     $path = "dot.notation.support";
     $expectedResult = ['dot.notation', 'support'];
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = InvokeMethod::onClass(MergeUsingDotNotationPath::class, 'splitPathInTwo', [$path]);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @covers ::buildListOfObjectMethods
  */
 public function testBuildsAListOfNonStaticMethodsWhenExaminingAnObject()
 {
     // ----------------------------------------------------------------
     // setup your test
     $expectedMethods = ['objectMethod1' => 'objectMethod1'];
     // ----------------------------------------------------------------
     // perform the change
     $actualMethods = InvokeMethod::onString(CallableMethodsList::class, 'buildListOfObjectMethods', [new CallableMethodsListTest_Target1()]);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedMethods, $actualMethods);
 }
 /**
  * @covers ::resetData
  */
 public function testNothingHappensWhenRemovingDataThatDoesNotExist()
 {
     // ----------------------------------------------------------------
     // setup your test
     $obj = new BaseContainer();
     $dataName = 'Value1';
     // ----------------------------------------------------------------
     // perform the change
     InvokeMethod::onObject($obj, 'resetData', [$dataName]);
     // ----------------------------------------------------------------
     // test the results
     $actualData = InvokeMethod::onObject($obj, 'hasData', [$dataName]);
     $this->assertFalse($actualData);
 }
 /**
  * @covers ::getPartFromObject
  * @covers ::getExtension
  */
 public function testCanExtendObjectUsingClassname()
 {
     // ----------------------------------------------------------------
     // setup your test
     $obj = (object) ["one" => 1, "two" => 2];
     $expectedResult = new stdClass();
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = InvokeMethod::onClass(DescendDotNotationPath::class, 'getPartFromObject', [$obj, "three", stdClass::class]);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
     $this->assertTrue(isset($obj->three));
     $this->assertTrue($obj->three instanceof stdClass);
 }
 /**
  * @covers ::onClass
  * @covers ::onString
  * @expectedException GanbaroDigital\UnitTestHelpers\Exceptions\E4xx_MethodIsNotStatic
  */
 public function testCanOnlyCallStaticMethodsByClass()
 {
     // ----------------------------------------------------------------
     // perform the change
     InvokeMethod::onString(InvokeMethodTest_TargetClass::class, 'publicMethod', []);
 }
 /**
  * @covers ::processTokens
  * @covers ::processTokensUsingProcessor
  */
 public function testSupportsMultipleTokenProcessors()
 {
     // ----------------------------------------------------------------
     // setup your test
     $state = new StreamState();
     $tokeniser = new StreamHeadTest_Tokeniser();
     $writer = new StreamHeadTest_TokenWriter();
     $processor1 = new StreamHeadTest_TokenDuplicator();
     $processor2 = new StreamHeadTest_TokenCounter();
     $stream = new BasicStreamHeadTest_HeadWithStringSupport($state, $tokeniser, [$processor1, $processor2], $writer);
     $expectedResult = "I have a string typesafe writer!";
     $token = new StreamHeadTest_StringToken($expectedResult);
     $expectedTokens = [$token, $token, $token, $token];
     // ----------------------------------------------------------------
     // perform the change
     $actualTokens = InvokeMethod::onObject($stream, 'processTokens', [[$token, $token]]);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedTokens, $actualTokens);
     $this->assertEquals(4, $state->tokensSeen);
 }
 /**
  * @coversNone
  */
 public function testSupportsIndependentCaches()
 {
     // ----------------------------------------------------------------
     // setup your test
     // make sure we start with a known state
     InvokeMethod::onString(CacheTypeA::class, 'resetCache');
     InvokeMethod::onString(CacheTypeB::class, 'resetCache');
     // we expect CacheTypeA to ONLY have these values
     $expectedResultsA = ['harry', 'sally', 'fred'];
     // we expect CacheTypeB to ONLY have these values
     $expectedResultsB = ['cod', 'haddock', 'trout'];
     // ----------------------------------------------------------------
     // perform the change
     foreach ($expectedResultsA as $key => $value) {
         InvokeMethod::onString(CacheTypeA::class, 'setInCache', [$key, $value]);
     }
     foreach ($expectedResultsB as $key => $value) {
         InvokeMethod::onString(CacheTypeB::class, 'setInCache', [$key, $value]);
     }
     // ----------------------------------------------------------------
     // test the results
     $actualResultsA = InvokeMethod::onString(CacheTypeA::class, 'getCache');
     $actualResultsB = InvokeMethod::onString(CacheTypeB::class, 'getCache');
     $this->assertEquals($expectedResultsA, $actualResultsA);
     $this->assertEquals($expectedResultsB, $actualResultsB);
 }
 /**
  * @covers ::findMethodToCall
  * @covers ::findFirstMatchingMethod
  * @expectedException GanbaroDigital\Reflection\Exceptions\E4xx_UnsupportedType
  */
 public function testThrowsAnExceptionWhenNoMatchFound()
 {
     // ----------------------------------------------------------------
     // setup your test
     $data = 100;
     $target = new FirstMethodMatchingTypeTest_Target2();
     // ----------------------------------------------------------------
     // perform the change
     InvokeMethod::onString(FirstMethodMatchingType::class, 'findMethodToCall', [$data, $target, 'from']);
 }