public function testMatchArrayParamByType() { $compiler = \Fbind\bindParams()->ofType('array')->to(function () { return ['hello', 'world']; }); $subject = function (array $foo, array $bar) { $this->assertSame(['hello', 'world'], $foo); $this->assertSame(['hello', 'world'], $bar); }; $compiled = $compiler->compile($subject); $compiled(); }
public function testBindingOnlyCalledOnce() { $compiler = \Fbind\bindParams()->ofType('array')->to(function () use(&$bindingWasCalled) { if ($bindingWasCalled) { $this->fail(); } $bindingWasCalled = true; return ['hello', 'world']; }); $subject = function (array $foo, array $bar) { $this->assertSame(['hello', 'world'], $foo); $this->assertSame(['hello', 'world'], $bar); }; $compiled = $compiler->compile($subject); $compiled(); }
public function testMultipleCompilers() { $now = time(); $timestampCompiler = \Fbind\bindParam('timestamp')->to(function () use($now) { return $now; }); $dateTimeCompiler = \Fbind\bindParams()->ofType(\DateTime::class)->to(function ($timestamp) { $dateTime = new DateTime(); $dateTime->setTimestamp($timestamp); return $dateTime; }); $subject = function ($timestamp, \DateTime $dateTime) use($now) { $this->assertEquals($now, $timestamp); $this->assertEquals($now, $dateTime->getTimestamp()); }; $compiled = $timestampCompiler->compile($dateTimeCompiler->compile($subject)); $compiled(); }