Exemple #1
0
 public function testSubjectIsAllowedParamName()
 {
     $compiler = \Fbind\bindParam('subject')->to(function () {
         return ['hello', 'world'];
     });
     $compiled = $compiler->compile(function (array $subject, array $bar) {
         $this->assertSame(['hello', 'world'], $subject);
         $this->assertSame(['foobar'], $bar);
     });
     $compiled(['foobar']);
 }
 public function testMatchArrayParamByType()
 {
     $compiler = \Fbind\bindParam('baz')->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);
     $this->assertSame($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();
 }