Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 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();
 }