/** * @dataProvider provideGenerateString */ public function testGenerateString($length, $characters) { $generator = $this->createGenerator(); $string = $generator->generateString($length, $characters); $this->assertSame($length, strlen($string)); $allStringCharactersInCharacters = f\every(f\partial('in_array', f\_(), str_split($characters)), str_split($string)); $this->assertTrue($allStringCharactersInCharacters); }
/** * @Given /^there are oauth2 clients:$/ */ public function thereAreOauthClients(TableNode $table) { $jsonDecode = function ($v) { return json_decode($v) ?: $v; }; $clients = f\map(f\partial('felpado\\map', $jsonDecode), $table->getHash()); f\each([$this, 'createOAuthClient'], $clients); }
/** * @Given /^there are oauth clients:$/ */ public function thereAreOauthClients(TableNode $table) { $jsonDecode = function ($v) { return json_decode($v) ?: $v; }; $clients = f\map(f\partial('felpado\\map', $jsonDecode), $table->getHash()); f\each(function ($params) { $this->getOAuthClientRepository()->add(new Client($params)); }, $clients); }
function function_doc_info_from_code($code) { $buildDoc = function ($raw, $doc) { return array('raw' => $raw, 'usage' => $doc[0], 'desc' => $doc[1], 'example' => $doc[2]); }; $docTemplate = array('', '', ''); $getRawDoc = function ($contents) { if (preg_match('@^/\\*\\*\\n(.*)\\n \\*/\\nfunction.@ms', $contents, $matches)) { return preg_replace('/^ \\* ?/m', '', $matches[1]); } return false; }; $rawDoc = $getRawDoc($code); if ($rawDoc === false) { return $buildDoc('', $docTemplate); } $processDoc = f\compose(f\partial('array_replace', $docTemplate), f\partial('explode', "\n\n", f\_(), 3)); $doc = $processDoc($rawDoc); return $buildDoc($rawDoc, $doc); }
/** * @expectedException \InvalidArgumentException */ public function testPartialWithPlaceholdersShouldThrowAnExceptionIfAPlaceholderValueIsMissing() { $o = f\partial(array($this, 'over'), f\_(), f\_(), 2); $o(10); }
<?php require __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\Finder\Finder; use felpado as f; $src = __DIR__ . '/../src'; $finder = Finder::create()->name('*.php')->name('*.xml')->in($src); $fixUses = f\partial('preg_replace', '/^(use Akamon\\\\OAuth2\\\\Server)(?:.+);$/m', ''); $fixNamespace = f\partial('preg_replace', '/(namespace Akamon\\\\OAuth2\\\\Server)(.+);/', '$1;'); $fixFullyQualifiedClasses = f\partial('preg_replace', '/(\\\\?Akamon\\\\OAuth2\\\\Server)(?:\\\\(\\w+))+(?!;)/m', '$1\\\\$2'); $fixTripleEof = function ($content) use(&$fixTripleEof) { $search = "/\n\n\n/m"; $replace = f\partial('preg_replace', $search, "\n\n"); return preg_match($search, $content) ? $fixTripleEof($replace($content)) : $content; }; $fix = f\compose($fixTripleEof, $fixFullyQualifiedClasses, $fixUses, $fixNamespace); $byePsr0 = function ($file) use($fix) { $newContent = $fix(file_get_contents($file)); file_put_contents($file, $newContent); }; f\each($byePsr0, $finder);
public function getNames() { return f\map(f\partial('felpado\\get', f\_(), 'name'), $this); }