repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
eloquent/phony
src/Call/Arguments.php
Arguments.has
public function has(int $index = 0): bool { if ($this->normalizeIndex($this->count, $index)) { return true; } return false; }
php
public function has(int $index = 0): bool { if ($this->normalizeIndex($this->count, $index)) { return true; } return false; }
[ "public", "function", "has", "(", "int", "$", "index", "=", "0", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "normalizeIndex", "(", "$", "this", "->", "count", ",", "$", "index", ")", ")", "{", "return", "true", ";", "}", "return", "fals...
Returns true if the argument index exists. Negative indices are offset from the end of the list. That is, `-1` indicates the last element, and `-2` indicates the second last element. @param int $index The index. @return bool True if the argument exists.
[ "Returns", "true", "if", "the", "argument", "index", "exists", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Arguments.php#L114-L121
train
eloquent/phony
src/Call/Arguments.php
Arguments.get
public function get(int $index = 0) { if (!$this->normalizeIndex($this->count, $index, $normalized)) { throw new UndefinedArgumentException($index); } return $this->arguments[$normalized]; }
php
public function get(int $index = 0) { if (!$this->normalizeIndex($this->count, $index, $normalized)) { throw new UndefinedArgumentException($index); } return $this->arguments[$normalized]; }
[ "public", "function", "get", "(", "int", "$", "index", "=", "0", ")", "{", "if", "(", "!", "$", "this", "->", "normalizeIndex", "(", "$", "this", "->", "count", ",", "$", "index", ",", "$", "normalized", ")", ")", "{", "throw", "new", "UndefinedArg...
Get an argument by index. Negative indices are offset from the end of the list. That is, `-1` indicates the last element, and `-2` indicates the second last element. @param int $index The index. @return mixed The argument. @throws UndefinedArgumentException If the requested argument is undefined.
[ "Get", "an", "argument", "by", "index", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Arguments.php#L134-L141
train
eloquent/phony
src/Mock/Handle/HandleTrait.php
HandleTrait.stub
public function stub(string $name, bool $isNewRule = true): StubVerifier { $key = strtolower($name); if (isset($this->state->stubs->$key)) { $stub = $this->state->stubs->$key; } else { $stub = $this->state->stubs->$key = $this->createStub($name); } if ($isNewRule) { $stub->closeRule(); } return $stub; }
php
public function stub(string $name, bool $isNewRule = true): StubVerifier { $key = strtolower($name); if (isset($this->state->stubs->$key)) { $stub = $this->state->stubs->$key; } else { $stub = $this->state->stubs->$key = $this->createStub($name); } if ($isNewRule) { $stub->closeRule(); } return $stub; }
[ "public", "function", "stub", "(", "string", "$", "name", ",", "bool", "$", "isNewRule", "=", "true", ")", ":", "StubVerifier", "{", "$", "key", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "state", "->...
Get a stub verifier. @param string $name The method name. @param bool $isNewRule True if a new rule should be started. @return StubVerifier The stub verifier. @throws MockException If the stub does not exist.
[ "Get", "a", "stub", "verifier", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleTrait.php#L109-L124
train
eloquent/phony
src/Mock/Handle/HandleTrait.php
HandleTrait.checkNoInteraction
public function checkNoInteraction(): ?EventCollection { foreach (get_object_vars($this->state->stubs) as $stub) { if ($stub->checkCalled()) { return null; } } return $this->assertionRecorder->createSuccess(); }
php
public function checkNoInteraction(): ?EventCollection { foreach (get_object_vars($this->state->stubs) as $stub) { if ($stub->checkCalled()) { return null; } } return $this->assertionRecorder->createSuccess(); }
[ "public", "function", "checkNoInteraction", "(", ")", ":", "?", "EventCollection", "{", "foreach", "(", "get_object_vars", "(", "$", "this", "->", "state", "->", "stubs", ")", "as", "$", "stub", ")", "{", "if", "(", "$", "stub", "->", "checkCalled", "(",...
Checks if there was no interaction with the mock. @return EventCollection|null The result.
[ "Checks", "if", "there", "was", "no", "interaction", "with", "the", "mock", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleTrait.php#L167-L176
train
eloquent/phony
src/Mock/Handle/HandleTrait.php
HandleTrait.noInteraction
public function noInteraction(): ?EventCollection { if ($result = $this->checkNoInteraction()) { return $result; } $calls = []; foreach (get_object_vars($this->state->stubs) as $stub) { $calls = array_merge($calls, $stub->allCalls()); } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderNoInteraction($this, $calls) ); }
php
public function noInteraction(): ?EventCollection { if ($result = $this->checkNoInteraction()) { return $result; } $calls = []; foreach (get_object_vars($this->state->stubs) as $stub) { $calls = array_merge($calls, $stub->allCalls()); } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderNoInteraction($this, $calls) ); }
[ "public", "function", "noInteraction", "(", ")", ":", "?", "EventCollection", "{", "if", "(", "$", "result", "=", "$", "this", "->", "checkNoInteraction", "(", ")", ")", "{", "return", "$", "result", ";", "}", "$", "calls", "=", "[", "]", ";", "forea...
Record an assertion failure unless there was no interaction with the mock. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Record", "an", "assertion", "failure", "unless", "there", "was", "no", "interaction", "with", "the", "mock", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleTrait.php#L184-L199
train
eloquent/phony
src/Mock/Handle/HandleTrait.php
HandleTrait.stopRecording
public function stopRecording(): Handle { foreach (get_object_vars($this->state->stubs) as $stub) { $stub->stopRecording(); } $this->state->isRecording = false; return $this; }
php
public function stopRecording(): Handle { foreach (get_object_vars($this->state->stubs) as $stub) { $stub->stopRecording(); } $this->state->isRecording = false; return $this; }
[ "public", "function", "stopRecording", "(", ")", ":", "Handle", "{", "foreach", "(", "get_object_vars", "(", "$", "this", "->", "state", "->", "stubs", ")", "as", "$", "stub", ")", "{", "$", "stub", "->", "stopRecording", "(", ")", ";", "}", "$", "th...
Stop recording calls. @return $this This handle.
[ "Stop", "recording", "calls", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleTrait.php#L206-L215
train
eloquent/phony
src/Mock/Handle/HandleTrait.php
HandleTrait.startRecording
public function startRecording(): Handle { foreach (get_object_vars($this->state->stubs) as $stub) { $stub->startRecording(); } $this->state->isRecording = true; return $this; }
php
public function startRecording(): Handle { foreach (get_object_vars($this->state->stubs) as $stub) { $stub->startRecording(); } $this->state->isRecording = true; return $this; }
[ "public", "function", "startRecording", "(", ")", ":", "Handle", "{", "foreach", "(", "get_object_vars", "(", "$", "this", "->", "state", "->", "stubs", ")", "as", "$", "stub", ")", "{", "$", "stub", "->", "startRecording", "(", ")", ";", "}", "$", "...
Start recording calls. @return $this This handle.
[ "Start", "recording", "calls", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleTrait.php#L222-L231
train
eloquent/phony
src/Invocation/InvocableInspector.php
InvocableInspector.callbackReflector
public function callbackReflector($callback): ReflectionFunctionAbstract { while ($callback instanceof WrappedInvocable) { $callback = $callback->callback(); } if (is_array($callback)) { return new ReflectionMethod($callback[0], $callback[1]); } if (is_string($callback) && false !== strpos($callback, '::')) { list($className, $methodName) = explode('::', $callback); return new ReflectionMethod($className, $methodName); } if (is_object($callback) && !$callback instanceof Closure) { return new ReflectionMethod($callback, '__invoke'); } return new ReflectionFunction($callback); }
php
public function callbackReflector($callback): ReflectionFunctionAbstract { while ($callback instanceof WrappedInvocable) { $callback = $callback->callback(); } if (is_array($callback)) { return new ReflectionMethod($callback[0], $callback[1]); } if (is_string($callback) && false !== strpos($callback, '::')) { list($className, $methodName) = explode('::', $callback); return new ReflectionMethod($className, $methodName); } if (is_object($callback) && !$callback instanceof Closure) { return new ReflectionMethod($callback, '__invoke'); } return new ReflectionFunction($callback); }
[ "public", "function", "callbackReflector", "(", "$", "callback", ")", ":", "ReflectionFunctionAbstract", "{", "while", "(", "$", "callback", "instanceof", "WrappedInvocable", ")", "{", "$", "callback", "=", "$", "callback", "->", "callback", "(", ")", ";", "}"...
Get the appropriate reflector for the supplied callback. @param callable $callback The callback. @return ReflectionFunctionAbstract The reflector. @throws ReflectionException If the callback cannot be reflected.
[ "Get", "the", "appropriate", "reflector", "for", "the", "supplied", "callback", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Invocation/InvocableInspector.php#L41-L62
train
eloquent/phony
src/Difference/DifferenceEngine.php
DifferenceEngine.difference
public function difference(string $from, string $to): string { $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; $from = preg_split('/(\W+)/u', $from, -1, $flags); $to = preg_split('/(\W+)/u', $to, -1, $flags); $matcher = new DifferenceSequenceMatcher($from, $to); $diff = ''; foreach ($matcher->getOpcodes() as $opcode) { list($tag, $i1, $i2, $j1, $j2) = $opcode; if ($tag === 'equal') { $diff .= implode(array_slice($from, $i1, $i2 - $i1)); } else { if ($tag === 'replace' || $tag === 'delete') { $diff .= $this->removeStart . implode(array_slice($from, $i1, $i2 - $i1)) . $this->removeEnd; } if ($tag === 'replace' || $tag === 'insert') { $diff .= $this->addStart . implode(array_slice($to, $j1, $j2 - $j1)) . $this->addEnd; } } } return $diff; }
php
public function difference(string $from, string $to): string { $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; $from = preg_split('/(\W+)/u', $from, -1, $flags); $to = preg_split('/(\W+)/u', $to, -1, $flags); $matcher = new DifferenceSequenceMatcher($from, $to); $diff = ''; foreach ($matcher->getOpcodes() as $opcode) { list($tag, $i1, $i2, $j1, $j2) = $opcode; if ($tag === 'equal') { $diff .= implode(array_slice($from, $i1, $i2 - $i1)); } else { if ($tag === 'replace' || $tag === 'delete') { $diff .= $this->removeStart . implode(array_slice($from, $i1, $i2 - $i1)) . $this->removeEnd; } if ($tag === 'replace' || $tag === 'insert') { $diff .= $this->addStart . implode(array_slice($to, $j1, $j2 - $j1)) . $this->addEnd; } } } return $diff; }
[ "public", "function", "difference", "(", "string", "$", "from", ",", "string", "$", "to", ")", ":", "string", "{", "$", "flags", "=", "PREG_SPLIT_DELIM_CAPTURE", "|", "PREG_SPLIT_NO_EMPTY", ";", "$", "from", "=", "preg_split", "(", "'/(\\W+)/u'", ",", "$", ...
Get the difference between the supplied strings. @param string $from The from value. @param string $to The to value. @return string The difference.
[ "Get", "the", "difference", "between", "the", "supplied", "strings", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Difference/DifferenceEngine.php#L76-L108
train
eloquent/phony
src/Assertion/AssertionRenderer.php
AssertionRenderer.instance
public static function instance(): self { if (!self::$instance) { self::$instance = new self( MatcherVerifier::instance(), InlineExporter::instance(), DifferenceEngine::instance(), FeatureDetector::instance() ); } return self::$instance; }
php
public static function instance(): self { if (!self::$instance) { self::$instance = new self( MatcherVerifier::instance(), InlineExporter::instance(), DifferenceEngine::instance(), FeatureDetector::instance() ); } return self::$instance; }
[ "public", "static", "function", "instance", "(", ")", ":", "self", "{", "if", "(", "!", "self", "::", "$", "instance", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", "MatcherVerifier", "::", "instance", "(", ")", ",", "InlineExporter...
Get the static instance of this renderer. @return AssertionRenderer The static renderer.
[ "Get", "the", "static", "instance", "of", "this", "renderer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Assertion/AssertionRenderer.php#L47-L59
train
eloquent/phony
src/Assertion/AssertionRenderer.php
AssertionRenderer.renderMatchers
public function renderMatchers(array $matchers): string { if (count($matchers) < 1) { return '<none>'; } $rendered = []; foreach ($matchers as $matcher) { $rendered[] = $matcher->describe($this->exporter); } return implode(', ', $rendered); }
php
public function renderMatchers(array $matchers): string { if (count($matchers) < 1) { return '<none>'; } $rendered = []; foreach ($matchers as $matcher) { $rendered[] = $matcher->describe($this->exporter); } return implode(', ', $rendered); }
[ "public", "function", "renderMatchers", "(", "array", "$", "matchers", ")", ":", "string", "{", "if", "(", "count", "(", "$", "matchers", ")", "<", "1", ")", "{", "return", "'<none>'", ";", "}", "$", "rendered", "=", "[", "]", ";", "foreach", "(", ...
Render a sequence of matchers. @param array<Matchable> $matchers The matchers. @return string The rendered matchers.
[ "Render", "a", "sequence", "of", "matchers", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Assertion/AssertionRenderer.php#L3655-L3668
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.duration
public function duration(): ?float { $endTime = $this->call->endTime(); if (null === $endTime) { return null; } return $endTime - $this->call->time(); }
php
public function duration(): ?float { $endTime = $this->call->endTime(); if (null === $endTime) { return null; } return $endTime - $this->call->time(); }
[ "public", "function", "duration", "(", ")", ":", "?", "float", "{", "$", "endTime", "=", "$", "this", "->", "call", "->", "endTime", "(", ")", ";", "if", "(", "null", "===", "$", "endTime", ")", "{", "return", "null", ";", "}", "return", "$", "en...
Get the call duration. @return float|null The call duration in seconds, or null if the call has not yet completed.
[ "Get", "the", "call", "duration", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L535-L544
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.responseDuration
public function responseDuration(): ?float { $responseTime = $this->call->responseTime(); if (null === $responseTime) { return null; } return $responseTime - $this->call->time(); }
php
public function responseDuration(): ?float { $responseTime = $this->call->responseTime(); if (null === $responseTime) { return null; } return $responseTime - $this->call->time(); }
[ "public", "function", "responseDuration", "(", ")", ":", "?", "float", "{", "$", "responseTime", "=", "$", "this", "->", "call", "->", "responseTime", "(", ")", ";", "if", "(", "null", "===", "$", "responseTime", ")", "{", "return", "null", ";", "}", ...
Get the call response duration. @return float|null The call response duration in seconds, or null if the call has not yet responded.
[ "Get", "the", "call", "response", "duration", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L551-L560
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.calledWith
public function calledWith(...$arguments): ?EventCollection { $cardinality = $this->cardinality; $matchers = $this->matcherFactory->adaptAll($arguments); if ($result = $this->checkCalledWith(...$matchers)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderCalledWith($this->call, $cardinality, $matchers) ); }
php
public function calledWith(...$arguments): ?EventCollection { $cardinality = $this->cardinality; $matchers = $this->matcherFactory->adaptAll($arguments); if ($result = $this->checkCalledWith(...$matchers)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderCalledWith($this->call, $cardinality, $matchers) ); }
[ "public", "function", "calledWith", "(", "...", "$", "arguments", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "$", "matchers", "=", "$", "this", "->", "matcherFactory", "->", "adaptAll", "(", "$", ...
Throws an exception unless called with the supplied arguments. @param mixed ...$argument The arguments. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws InvalidCardinalityException If the cardinality is invalid. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "called", "with", "the", "supplied", "arguments", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L607-L620
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.checkResponded
public function checkResponded(): ?EventCollection { $cardinality = $this->resetCardinality()->assertSingular(); $responseEvent = $this->call->responseEvent(); list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, $responseEvent); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkResponded(): ?EventCollection { $cardinality = $this->resetCardinality()->assertSingular(); $responseEvent = $this->call->responseEvent(); list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, $responseEvent); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkResponded", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", "->", "assertSingular", "(", ")", ";", "$", "responseEvent", "=", "$", "this", "->", "call", "->",...
Checks if this call responded. @return EventCollection|null The result. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Checks", "if", "this", "call", "responded", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L628-L641
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.checkCompleted
public function checkCompleted(): ?EventCollection { $cardinality = $this->resetCardinality()->assertSingular(); $endEvent = $this->call->endEvent(); list($matchCount, $matchingEvents) = $this->matchIf($endEvent, $endEvent); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkCompleted(): ?EventCollection { $cardinality = $this->resetCardinality()->assertSingular(); $endEvent = $this->call->endEvent(); list($matchCount, $matchingEvents) = $this->matchIf($endEvent, $endEvent); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkCompleted", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", "->", "assertSingular", "(", ")", ";", "$", "endEvent", "=", "$", "this", "->", "call", "->", "e...
Checks if this call completed. @return EventCollection|null The result. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Checks", "if", "this", "call", "completed", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L669-L682
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.completed
public function completed(): ?EventCollection { $cardinality = $this->cardinality; if ($result = $this->checkCompleted()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderCompleted($this->call, $cardinality) ); }
php
public function completed(): ?EventCollection { $cardinality = $this->cardinality; if ($result = $this->checkCompleted()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderCompleted($this->call, $cardinality) ); }
[ "public", "function", "completed", "(", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "result", "=", "$", "this", "->", "checkCompleted", "(", ")", ")", "{", "return", "$", "resul...
Throws an exception unless this call completed. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws InvalidCardinalityException If the cardinality is invalid. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "this", "call", "completed", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L691-L702
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.checkReturned
public function checkReturned($value = null): ?EventCollection { $cardinality = $this->resetCardinality()->assertSingular(); if ($responseEvent = $this->call->responseEvent()) { list($exception, $returnValue) = $this->call->response(); $hasReturned = !$exception; } else { $returnValue = null; $hasReturned = false; } if (0 === func_num_args()) { list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, $hasReturned); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; } $value = $this->matcherFactory->adapt($value); list($matchCount, $matchingEvents) = $this->matchIf( $responseEvent, $hasReturned && $value->matches($returnValue) ); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkReturned($value = null): ?EventCollection { $cardinality = $this->resetCardinality()->assertSingular(); if ($responseEvent = $this->call->responseEvent()) { list($exception, $returnValue) = $this->call->response(); $hasReturned = !$exception; } else { $returnValue = null; $hasReturned = false; } if (0 === func_num_args()) { list($matchCount, $matchingEvents) = $this->matchIf($responseEvent, $hasReturned); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; } $value = $this->matcherFactory->adapt($value); list($matchCount, $matchingEvents) = $this->matchIf( $responseEvent, $hasReturned && $value->matches($returnValue) ); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkReturned", "(", "$", "value", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", "->", "assertSingular", "(", ")", ";", "if", "(", "$", "responseEvent", ...
Checks if this call returned the supplied value. When called with no arguments, this method simply checks that the call returned any value. @param mixed $value The value. @return EventCollection|null The result. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Checks", "if", "this", "call", "returned", "the", "supplied", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L715-L751
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.returned
public function returned($value = null): ?EventCollection { $cardinality = $this->cardinality; $argumentCount = func_num_args(); if (0 === $argumentCount) { $arguments = []; } else { $value = $this->matcherFactory->adapt($value); $arguments = [$value]; } if ($result = $this->checkReturned(...$arguments)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderReturned($this->call, $cardinality, $value) ); }
php
public function returned($value = null): ?EventCollection { $cardinality = $this->cardinality; $argumentCount = func_num_args(); if (0 === $argumentCount) { $arguments = []; } else { $value = $this->matcherFactory->adapt($value); $arguments = [$value]; } if ($result = $this->checkReturned(...$arguments)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderReturned($this->call, $cardinality, $value) ); }
[ "public", "function", "returned", "(", "$", "value", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "$", "argumentCount", "=", "func_num_args", "(", ")", ";", "if", "(", "0", "===", "...
Throws an exception unless this call returned the supplied value. When called with no arguments, this method simply checks that the call returned any value. @param mixed $value The value. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws InvalidCardinalityException If the cardinality is invalid. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "this", "call", "returned", "the", "supplied", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L765-L785
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.threw
public function threw($type = null): ?EventCollection { $cardinality = $this->cardinality; if ($type instanceof InstanceHandle) { $type = $type->get(); } if ($type instanceof Throwable) { $type = $this->matcherFactory->equalTo($type, true); } elseif ($this->matcherFactory->isMatcher($type)) { $type = $this->matcherFactory->adapt($type); } if ($result = $this->checkThrew($type)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderThrew($this->call, $cardinality, $type) ); }
php
public function threw($type = null): ?EventCollection { $cardinality = $this->cardinality; if ($type instanceof InstanceHandle) { $type = $type->get(); } if ($type instanceof Throwable) { $type = $this->matcherFactory->equalTo($type, true); } elseif ($this->matcherFactory->isMatcher($type)) { $type = $this->matcherFactory->adapt($type); } if ($result = $this->checkThrew($type)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderThrew($this->call, $cardinality, $type) ); }
[ "public", "function", "threw", "(", "$", "type", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "type", "instanceof", "InstanceHandle", ")", "{", "$", "type", "=", "$"...
Throws an exception unless this call threw an exception of the supplied type. @param Matcher|Throwable|string|null $type An exception to match, the type of exception, or null for any exception. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws InvalidCardinalityException If the cardinality is invalid. @throws InvalidArgumentException If the type is invalid. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "this", "call", "threw", "an", "exception", "of", "the", "supplied", "type", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L875-L897
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.checkGenerated
public function checkGenerated(): ?GeneratorVerifier { $cardinality = $this->resetCardinality()->assertSingular(); if ($this->call->responseEvent()) { list(, $returnValue) = $this->call->response(); $isMatch = $returnValue instanceof Generator; } else { $isMatch = false; } list($matchCount, $matchingEvents) = $this->matchIf($this->call, $isMatch); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->generatorVerifierFactory ->create($this->call, $matchingEvents) ); } return null; }
php
public function checkGenerated(): ?GeneratorVerifier { $cardinality = $this->resetCardinality()->assertSingular(); if ($this->call->responseEvent()) { list(, $returnValue) = $this->call->response(); $isMatch = $returnValue instanceof Generator; } else { $isMatch = false; } list($matchCount, $matchingEvents) = $this->matchIf($this->call, $isMatch); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->generatorVerifierFactory ->create($this->call, $matchingEvents) ); } return null; }
[ "public", "function", "checkGenerated", "(", ")", ":", "?", "GeneratorVerifier", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", "->", "assertSingular", "(", ")", ";", "if", "(", "$", "this", "->", "call", "->", "responseEven...
Checks if this call returned a generator. @return GeneratorVerifier|null The result. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Checks", "if", "this", "call", "returned", "a", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L905-L928
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.checkIterated
public function checkIterated(): ?IterableVerifier { $cardinality = $this->resetCardinality()->assertSingular(); if ($this->call->responseEvent()) { list(, $returnValue) = $this->call->response(); $isMatch = $returnValue instanceof Traversable || is_array($returnValue); } else { $isMatch = false; } list($matchCount, $matchingEvents) = $this->matchIf($this->call, $isMatch); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->iterableVerifierFactory ->create($this->call, $matchingEvents) ); } return null; }
php
public function checkIterated(): ?IterableVerifier { $cardinality = $this->resetCardinality()->assertSingular(); if ($this->call->responseEvent()) { list(, $returnValue) = $this->call->response(); $isMatch = $returnValue instanceof Traversable || is_array($returnValue); } else { $isMatch = false; } list($matchCount, $matchingEvents) = $this->matchIf($this->call, $isMatch); if ($cardinality->matches($matchCount, 1)) { return $this->assertionRecorder->createSuccessFromEventCollection( $this->iterableVerifierFactory ->create($this->call, $matchingEvents) ); } return null; }
[ "public", "function", "checkIterated", "(", ")", ":", "?", "IterableVerifier", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", "->", "assertSingular", "(", ")", ";", "if", "(", "$", "this", "->", "call", "->", "responseEvent"...
Checks if this call returned an iterable. @return IterableVerifier|null The result. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Checks", "if", "this", "call", "returned", "an", "iterable", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L956-L980
train
eloquent/phony
src/Call/CallVerifier.php
CallVerifier.iterated
public function iterated(): ?IterableVerifier { $cardinality = $this->cardinality; if ($result = $this->checkIterated()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderIterated($this->call, $cardinality) ); }
php
public function iterated(): ?IterableVerifier { $cardinality = $this->cardinality; if ($result = $this->checkIterated()) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderIterated($this->call, $cardinality) ); }
[ "public", "function", "iterated", "(", ")", ":", "?", "IterableVerifier", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "result", "=", "$", "this", "->", "checkIterated", "(", ")", ")", "{", "return", "$", "result...
Throws an exception unless this call returned an iterable. @return IterableVerifier The result, or null if the assertion recorder does not throw exceptions. @throws InvalidCardinalityException If the cardinality is invalid. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "this", "call", "returned", "an", "iterable", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifier.php#L989-L1000
train
eloquent/phony
src/Assertion/Exception/AssertionException.php
AssertionException.tracePhonyCall
public static function tracePhonyCall(array $trace): array { $prefix = 'Eloquent\Phony\\'; for ($i = count($trace) - 1; $i >= 0; --$i) { $entry = $trace[$i]; if (isset($entry['class'])) { if (0 === strpos($entry['class'], $prefix)) { return $entry; } } elseif (0 === strpos($entry['function'], $prefix)) { return $entry; } } return []; }
php
public static function tracePhonyCall(array $trace): array { $prefix = 'Eloquent\Phony\\'; for ($i = count($trace) - 1; $i >= 0; --$i) { $entry = $trace[$i]; if (isset($entry['class'])) { if (0 === strpos($entry['class'], $prefix)) { return $entry; } } elseif (0 === strpos($entry['function'], $prefix)) { return $entry; } } return []; }
[ "public", "static", "function", "tracePhonyCall", "(", "array", "$", "trace", ")", ":", "array", "{", "$", "prefix", "=", "'Eloquent\\Phony\\\\'", ";", "for", "(", "$", "i", "=", "count", "(", "$", "trace", ")", "-", "1", ";", "$", "i", ">=", "0", ...
Find the Phony entry point call in a stack trace. @param array $trace The stack trace. @return array The call, or an empty array if unable to determine the entry point.
[ "Find", "the", "Phony", "entry", "point", "call", "in", "a", "stack", "trace", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Assertion/Exception/AssertionException.php#L54-L71
train
iiifx-production/yii2-autocomplete-helper
source/Controller.php
Controller.actionIndex
public function actionIndex() { $this->showDescription(); try { $component = $this->getComponent(); $configList = $this->getConfig($component); $config = new Config([ 'files' => $configList, ]); $builder = new Builder([ 'components' => $config->getComponents(), 'template' => require __DIR__ . '/template.php', ]); if ($component->result === null) { $component->result = ($this->getDetector()->detect() === 'basic') ? '@app/_ide_components.php' : '@console/../_ide_components.php'; } $result = Yii::getAlias($component->result); $result = FileHelper::normalizePath($result); if ($builder->build($result)) { $this->stdout("Success: {$result}\n", Console::FG_GREEN); } else { $this->stdout("Fail!\n", Console::FG_RED); } } catch (Exception $exception) { $this->stdout($exception->getMessage() . "\n\n", Console::FG_RED); $this->stdout("Please read the package documentation: https://github.com/iiifx-production/yii2-autocomplete-helper\n"); $this->stdout("or create new issue: https://github.com/iiifx-production/yii2-autocomplete-helper/issues/new\n"); } }
php
public function actionIndex() { $this->showDescription(); try { $component = $this->getComponent(); $configList = $this->getConfig($component); $config = new Config([ 'files' => $configList, ]); $builder = new Builder([ 'components' => $config->getComponents(), 'template' => require __DIR__ . '/template.php', ]); if ($component->result === null) { $component->result = ($this->getDetector()->detect() === 'basic') ? '@app/_ide_components.php' : '@console/../_ide_components.php'; } $result = Yii::getAlias($component->result); $result = FileHelper::normalizePath($result); if ($builder->build($result)) { $this->stdout("Success: {$result}\n", Console::FG_GREEN); } else { $this->stdout("Fail!\n", Console::FG_RED); } } catch (Exception $exception) { $this->stdout($exception->getMessage() . "\n\n", Console::FG_RED); $this->stdout("Please read the package documentation: https://github.com/iiifx-production/yii2-autocomplete-helper\n"); $this->stdout("or create new issue: https://github.com/iiifx-production/yii2-autocomplete-helper/issues/new\n"); } }
[ "public", "function", "actionIndex", "(", ")", "{", "$", "this", "->", "showDescription", "(", ")", ";", "try", "{", "$", "component", "=", "$", "this", "->", "getComponent", "(", ")", ";", "$", "configList", "=", "$", "this", "->", "getConfig", "(", ...
Generate IDE auto-completion file
[ "Generate", "IDE", "auto", "-", "completion", "file" ]
b8acae313bf14e13d6e2bd58cbc89ef0ad451d4c
https://github.com/iiifx-production/yii2-autocomplete-helper/blob/b8acae313bf14e13d6e2bd58cbc89ef0ad451d4c/source/Controller.php#L71-L101
train
eloquent/phony
src/Call/Event/CallEventFactory.php
CallEventFactory.createCalled
public function createCalled( $callback, Arguments $arguments ): CalledEvent { return new CalledEvent( $this->sequencer->next(), $this->clock->time(), $callback, $arguments ); }
php
public function createCalled( $callback, Arguments $arguments ): CalledEvent { return new CalledEvent( $this->sequencer->next(), $this->clock->time(), $callback, $arguments ); }
[ "public", "function", "createCalled", "(", "$", "callback", ",", "Arguments", "$", "arguments", ")", ":", "CalledEvent", "{", "return", "new", "CalledEvent", "(", "$", "this", "->", "sequencer", "->", "next", "(", ")", ",", "$", "this", "->", "clock", "-...
Create a new 'called' event. @param callable $callback The callback. @param Arguments $arguments The arguments. @return CalledEvent The newly created event.
[ "Create", "a", "new", "called", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Event/CallEventFactory.php#L55-L65
train
eloquent/phony
src/Call/Event/CallEventFactory.php
CallEventFactory.createReturned
public function createReturned($value): ReturnedEvent { return new ReturnedEvent( $this->sequencer->next(), $this->clock->time(), $value ); }
php
public function createReturned($value): ReturnedEvent { return new ReturnedEvent( $this->sequencer->next(), $this->clock->time(), $value ); }
[ "public", "function", "createReturned", "(", "$", "value", ")", ":", "ReturnedEvent", "{", "return", "new", "ReturnedEvent", "(", "$", "this", "->", "sequencer", "->", "next", "(", ")", ",", "$", "this", "->", "clock", "->", "time", "(", ")", ",", "$",...
Create a new 'returned' event. @param mixed $value The return value. @return ReturnedEvent The newly created event.
[ "Create", "a", "new", "returned", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Event/CallEventFactory.php#L74-L81
train
eloquent/phony
src/Call/Event/CallEventFactory.php
CallEventFactory.createThrew
public function createThrew(Throwable $exception): ThrewEvent { return new ThrewEvent( $this->sequencer->next(), $this->clock->time(), $exception ); }
php
public function createThrew(Throwable $exception): ThrewEvent { return new ThrewEvent( $this->sequencer->next(), $this->clock->time(), $exception ); }
[ "public", "function", "createThrew", "(", "Throwable", "$", "exception", ")", ":", "ThrewEvent", "{", "return", "new", "ThrewEvent", "(", "$", "this", "->", "sequencer", "->", "next", "(", ")", ",", "$", "this", "->", "clock", "->", "time", "(", ")", "...
Create a new 'thrown' event. @param Throwable $exception The thrown exception. @return ThrewEvent The newly created event.
[ "Create", "a", "new", "thrown", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Event/CallEventFactory.php#L90-L97
train
eloquent/phony
src/Call/Event/CallEventFactory.php
CallEventFactory.createProduced
public function createProduced($key, $value): ProducedEvent { return new ProducedEvent( $this->sequencer->next(), $this->clock->time(), $key, $value ); }
php
public function createProduced($key, $value): ProducedEvent { return new ProducedEvent( $this->sequencer->next(), $this->clock->time(), $key, $value ); }
[ "public", "function", "createProduced", "(", "$", "key", ",", "$", "value", ")", ":", "ProducedEvent", "{", "return", "new", "ProducedEvent", "(", "$", "this", "->", "sequencer", "->", "next", "(", ")", ",", "$", "this", "->", "clock", "->", "time", "(...
Create a new 'produced' event. @param mixed $key The produced key. @param mixed $value The produced value. @return ProducedEvent The newly created event.
[ "Create", "a", "new", "produced", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Event/CallEventFactory.php#L117-L125
train
eloquent/phony
src/Call/Event/CallEventFactory.php
CallEventFactory.createReceived
public function createReceived($value): ReceivedEvent { return new ReceivedEvent( $this->sequencer->next(), $this->clock->time(), $value ); }
php
public function createReceived($value): ReceivedEvent { return new ReceivedEvent( $this->sequencer->next(), $this->clock->time(), $value ); }
[ "public", "function", "createReceived", "(", "$", "value", ")", ":", "ReceivedEvent", "{", "return", "new", "ReceivedEvent", "(", "$", "this", "->", "sequencer", "->", "next", "(", ")", ",", "$", "this", "->", "clock", "->", "time", "(", ")", ",", "$",...
Create a new 'received' event. @param mixed $value The received value. @return ReceivedEvent The newly created event.
[ "Create", "a", "new", "received", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Event/CallEventFactory.php#L134-L141
train
eloquent/phony
src/Call/Event/CallEventFactory.php
CallEventFactory.createReceivedException
public function createReceivedException( Throwable $exception ): ReceivedExceptionEvent { return new ReceivedExceptionEvent( $this->sequencer->next(), $this->clock->time(), $exception ); }
php
public function createReceivedException( Throwable $exception ): ReceivedExceptionEvent { return new ReceivedExceptionEvent( $this->sequencer->next(), $this->clock->time(), $exception ); }
[ "public", "function", "createReceivedException", "(", "Throwable", "$", "exception", ")", ":", "ReceivedExceptionEvent", "{", "return", "new", "ReceivedExceptionEvent", "(", "$", "this", "->", "sequencer", "->", "next", "(", ")", ",", "$", "this", "->", "clock",...
Create a new 'received exception' event. @param Throwable $exception The received exception. @return ReceivedExceptionEvent The newly created event.
[ "Create", "a", "new", "received", "exception", "event", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Event/CallEventFactory.php#L150-L158
train
eloquent/phony
src/Sequencer/Sequencer.php
Sequencer.sequence
public static function sequence(string $name): self { if (!isset(self::$instances[$name])) { self::$instances[$name] = new self(); } return self::$instances[$name]; }
php
public static function sequence(string $name): self { if (!isset(self::$instances[$name])) { self::$instances[$name] = new self(); } return self::$instances[$name]; }
[ "public", "static", "function", "sequence", "(", "string", "$", "name", ")", ":", "self", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "name", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "name", "...
Get a sequencer for a named sequence. @param string $name The sequence name. @return Sequencer The sequencer.
[ "Get", "a", "sequencer", "for", "a", "named", "sequence", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Sequencer/Sequencer.php#L19-L26
train
eloquent/phony
src/Facade/FacadeTrait.php
FacadeTrait.mock
public static function mock($types = []): InstanceHandle { $container = self::$globals::$container; return $container->handleFactory->instanceHandle( $container->mockBuilderFactory->create($types)->full() ); }
php
public static function mock($types = []): InstanceHandle { $container = self::$globals::$container; return $container->handleFactory->instanceHandle( $container->mockBuilderFactory->create($types)->full() ); }
[ "public", "static", "function", "mock", "(", "$", "types", "=", "[", "]", ")", ":", "InstanceHandle", "{", "$", "container", "=", "self", "::", "$", "globals", "::", "$", "container", ";", "return", "$", "container", "->", "handleFactory", "->", "instanc...
Create a new full mock, and return a handle. Each value in `$types` can be either a class name, or an ad hoc mock definition. If only a single type is being mocked, the class name or definition can be passed without being wrapped in an array. @param mixed $types The types to mock. @return InstanceHandle A handle around the new mock.
[ "Create", "a", "new", "full", "mock", "and", "return", "a", "handle", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Facade/FacadeTrait.php#L59-L66
train
eloquent/phony
src/Facade/FacadeTrait.php
FacadeTrait.partialMock
public static function partialMock( $types = [], $arguments = [] ): InstanceHandle { $container = self::$globals::$container; return $container->handleFactory->instanceHandle( $container->mockBuilderFactory->create($types) ->partialWith($arguments) ); }
php
public static function partialMock( $types = [], $arguments = [] ): InstanceHandle { $container = self::$globals::$container; return $container->handleFactory->instanceHandle( $container->mockBuilderFactory->create($types) ->partialWith($arguments) ); }
[ "public", "static", "function", "partialMock", "(", "$", "types", "=", "[", "]", ",", "$", "arguments", "=", "[", "]", ")", ":", "InstanceHandle", "{", "$", "container", "=", "self", "::", "$", "globals", "::", "$", "container", ";", "return", "$", "...
Create a new partial mock, and return a handle. Each value in `$types` can be either a class name, or an ad hoc mock definition. If only a single type is being mocked, the class name or definition can be passed without being wrapped in an array. Omitting `$arguments` will cause the original constructor to be called with an empty argument list. However, if a `null` value is supplied for `$arguments`, the original constructor will not be called at all. @param mixed $types The types to mock. @param Arguments|array|null $arguments The constructor arguments, or null to bypass the constructor. @return InstanceHandle A handle around the new mock.
[ "Create", "a", "new", "partial", "mock", "and", "return", "a", "handle", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Facade/FacadeTrait.php#L84-L94
train
eloquent/phony
src/Facade/FacadeTrait.php
FacadeTrait.spyGlobal
public static function spyGlobal( string $function, string $namespace ): SpyVerifier { $container = self::$globals::$container; return $container->spyVerifierFactory ->createGlobal($function, $namespace); }
php
public static function spyGlobal( string $function, string $namespace ): SpyVerifier { $container = self::$globals::$container; return $container->spyVerifierFactory ->createGlobal($function, $namespace); }
[ "public", "static", "function", "spyGlobal", "(", "string", "$", "function", ",", "string", "$", "namespace", ")", ":", "SpyVerifier", "{", "$", "container", "=", "self", "::", "$", "globals", "::", "$", "container", ";", "return", "$", "container", "->", ...
Create a spy of a function in the global namespace, and declare it as a function in another namespace. @param string $function The name of the function in the global namespace. @param string $namespace The namespace in which to create the new function. @return SpyVerifier The new spy.
[ "Create", "a", "spy", "of", "a", "function", "in", "the", "global", "namespace", "and", "declare", "it", "as", "a", "function", "in", "another", "namespace", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Facade/FacadeTrait.php#L149-L157
train
eloquent/phony
src/Facade/FacadeTrait.php
FacadeTrait.stubGlobal
public static function stubGlobal( string $function, string $namespace ): StubVerifier { $container = self::$globals::$container; return $container->stubVerifierFactory ->createGlobal($function, $namespace); }
php
public static function stubGlobal( string $function, string $namespace ): StubVerifier { $container = self::$globals::$container; return $container->stubVerifierFactory ->createGlobal($function, $namespace); }
[ "public", "static", "function", "stubGlobal", "(", "string", "$", "function", ",", "string", "$", "namespace", ")", ":", "StubVerifier", "{", "$", "container", "=", "self", "::", "$", "globals", "::", "$", "container", ";", "return", "$", "container", "->"...
Create a stub of a function in the global namespace, and declare it as a function in another namespace. Stubs created via this function do not forward to the original function by default. This differs from stubs created by other methods. @param string $function The name of the function in the global namespace. @param string $namespace The namespace in which to create the new function. @return StubVerifier The new stub.
[ "Create", "a", "stub", "of", "a", "function", "in", "the", "global", "namespace", "and", "declare", "it", "as", "a", "function", "in", "another", "namespace", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Facade/FacadeTrait.php#L185-L193
train
eloquent/phony
src/Facade/FacadeTrait.php
FacadeTrait.emptyValue
public static function emptyValue(ReflectionType $type) { $container = self::$globals::$container; return $container->emptyValueFactory->fromType($type); }
php
public static function emptyValue(ReflectionType $type) { $container = self::$globals::$container; return $container->emptyValueFactory->fromType($type); }
[ "public", "static", "function", "emptyValue", "(", "ReflectionType", "$", "type", ")", "{", "$", "container", "=", "self", "::", "$", "globals", "::", "$", "container", ";", "return", "$", "container", "->", "emptyValueFactory", "->", "fromType", "(", "$", ...
Get an "empty" value for the supplied type. @param ReflectionType $type The type. @return mixed An "empty" value of the supplied type.
[ "Get", "an", "empty", "value", "for", "the", "supplied", "type", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Facade/FacadeTrait.php#L336-L341
train
eloquent/phony
src/Facade/FacadeTrait.php
FacadeTrait.setExportDepth
public static function setExportDepth(int $depth): int { $container = self::$globals::$container; return $container->exporter->setDepth($depth); }
php
public static function setExportDepth(int $depth): int { $container = self::$globals::$container; return $container->exporter->setDepth($depth); }
[ "public", "static", "function", "setExportDepth", "(", "int", "$", "depth", ")", ":", "int", "{", "$", "container", "=", "self", "::", "$", "globals", "::", "$", "container", ";", "return", "$", "container", "->", "exporter", "->", "setDepth", "(", "$", ...
Set the default export depth. Negative depths are treated as infinite depth. @param int $depth The depth. @return int The previous depth.
[ "Set", "the", "default", "export", "depth", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Facade/FacadeTrait.php#L352-L357
train
eloquent/phony
src/Stub/StubRule.php
StubRule.next
public function next(): Answer { if ($this->calledCount > $this->lastIndex) { $index = $this->lastIndex; } else { $index = $this->calledCount; } ++$this->calledCount; if ( !isset($this->answers[$index]) || !$this->answers[$index]->primaryRequest() ) { throw new UndefinedAnswerException(); } return $this->answers[$index]; }
php
public function next(): Answer { if ($this->calledCount > $this->lastIndex) { $index = $this->lastIndex; } else { $index = $this->calledCount; } ++$this->calledCount; if ( !isset($this->answers[$index]) || !$this->answers[$index]->primaryRequest() ) { throw new UndefinedAnswerException(); } return $this->answers[$index]; }
[ "public", "function", "next", "(", ")", ":", "Answer", "{", "if", "(", "$", "this", "->", "calledCount", ">", "$", "this", "->", "lastIndex", ")", "{", "$", "index", "=", "$", "this", "->", "lastIndex", ";", "}", "else", "{", "$", "index", "=", "...
Get the next answer. @return Answer The answer. @throws UndefinedAnswerException If an undefined or incomplete answer is encountered.
[ "Get", "the", "next", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubRule.php#L57-L75
train
eloquent/phony
src/Matcher/WildcardMatcher.php
WildcardMatcher.instance
public static function instance(): self { if (!self::$instance) { self::$instance = new self(AnyMatcher::instance(), 0, -1); } return self::$instance; }
php
public static function instance(): self { if (!self::$instance) { self::$instance = new self(AnyMatcher::instance(), 0, -1); } return self::$instance; }
[ "public", "static", "function", "instance", "(", ")", ":", "self", "{", "if", "(", "!", "self", "::", "$", "instance", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", "AnyMatcher", "::", "instance", "(", ")", ",", "0", ",", "-", ...
Get the static instance of this matcher. @return WildcardMatcher The static matcher.
[ "Get", "the", "static", "instance", "of", "this", "matcher", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/WildcardMatcher.php#L19-L26
train
eloquent/phony
src/Mock/MockGenerator.php
MockGenerator.instance
public static function instance(): self { if (!self::$instance) { self::$instance = new self( Sequencer::sequence('mock-class-label'), FunctionSignatureInspector::instance(), FeatureDetector::instance() ); } return self::$instance; }
php
public static function instance(): self { if (!self::$instance) { self::$instance = new self( Sequencer::sequence('mock-class-label'), FunctionSignatureInspector::instance(), FeatureDetector::instance() ); } return self::$instance; }
[ "public", "static", "function", "instance", "(", ")", ":", "self", "{", "if", "(", "!", "self", "::", "$", "instance", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", "Sequencer", "::", "sequence", "(", "'mock-class-label'", ")", ",",...
Get the static instance of this generator. @return MockGenerator The static generator.
[ "Get", "the", "static", "instance", "of", "this", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockGenerator.php#L23-L34
train
eloquent/phony
src/Mock/MockGenerator.php
MockGenerator.generateClassName
public function generateClassName(MockDefinition $definition): string { $className = $definition->className(); if ('' !== $className) { return $className; } $className = 'PhonyMock'; $parentClassName = $definition->parentClassName(); if ('' !== $parentClassName) { $subject = $parentClassName; } elseif ($interfaceNames = $definition->interfaceNames()) { $subject = $interfaceNames[0]; } elseif ($traitNames = $definition->traitNames()) { $subject = $traitNames[0]; } else { $subject = null; } if (null !== $subject) { $subjectAtoms = preg_split('/[_\\\\]/', $subject); $className .= '_' . array_pop($subjectAtoms); } $className .= '_' . $this->labelSequencer->next(); return $className; }
php
public function generateClassName(MockDefinition $definition): string { $className = $definition->className(); if ('' !== $className) { return $className; } $className = 'PhonyMock'; $parentClassName = $definition->parentClassName(); if ('' !== $parentClassName) { $subject = $parentClassName; } elseif ($interfaceNames = $definition->interfaceNames()) { $subject = $interfaceNames[0]; } elseif ($traitNames = $definition->traitNames()) { $subject = $traitNames[0]; } else { $subject = null; } if (null !== $subject) { $subjectAtoms = preg_split('/[_\\\\]/', $subject); $className .= '_' . array_pop($subjectAtoms); } $className .= '_' . $this->labelSequencer->next(); return $className; }
[ "public", "function", "generateClassName", "(", "MockDefinition", "$", "definition", ")", ":", "string", "{", "$", "className", "=", "$", "definition", "->", "className", "(", ")", ";", "if", "(", "''", "!==", "$", "className", ")", "{", "return", "$", "...
Generate a mock class name. @param MockDefinition $definition The definition. @return string The mock class name.
[ "Generate", "a", "mock", "class", "name", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockGenerator.php#L60-L89
train
eloquent/phony
src/Mock/MockGenerator.php
MockGenerator.generate
public function generate( MockDefinition $definition, string $className = '' ): string { if ('' === $className) { $className = $this->generateClassName($definition); } $source = $this->generateHeader($definition, $className) . $this->generateConstants($definition) . $this->generateMethods( $definition->methods()->publicStaticMethods() ) . $this->generateMagicCallStatic($definition) . $this->generateStructors($definition) . $this->generateMethods($definition->methods()->publicMethods()) . $this->generateMagicCall($definition) . $this->generateMethods( $definition->methods()->protectedStaticMethods() ) . $this->generateMethods($definition->methods()->protectedMethods()) . $this->generateCallParentMethods($definition) . $this->generateProperties($definition) . "\n}\n"; // @codeCoverageIgnoreStart if (PHP_EOL !== "\n") { $source = str_replace("\n", PHP_EOL, $source); } // @codeCoverageIgnoreEnd return $source; }
php
public function generate( MockDefinition $definition, string $className = '' ): string { if ('' === $className) { $className = $this->generateClassName($definition); } $source = $this->generateHeader($definition, $className) . $this->generateConstants($definition) . $this->generateMethods( $definition->methods()->publicStaticMethods() ) . $this->generateMagicCallStatic($definition) . $this->generateStructors($definition) . $this->generateMethods($definition->methods()->publicMethods()) . $this->generateMagicCall($definition) . $this->generateMethods( $definition->methods()->protectedStaticMethods() ) . $this->generateMethods($definition->methods()->protectedMethods()) . $this->generateCallParentMethods($definition) . $this->generateProperties($definition) . "\n}\n"; // @codeCoverageIgnoreStart if (PHP_EOL !== "\n") { $source = str_replace("\n", PHP_EOL, $source); } // @codeCoverageIgnoreEnd return $source; }
[ "public", "function", "generate", "(", "MockDefinition", "$", "definition", ",", "string", "$", "className", "=", "''", ")", ":", "string", "{", "if", "(", "''", "===", "$", "className", ")", "{", "$", "className", "=", "$", "this", "->", "generateClassN...
Generate a mock class and return the source code. @param MockDefinition $definition The definition. @param string $className The class name. @return string The source code.
[ "Generate", "a", "mock", "class", "and", "return", "the", "source", "code", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockGenerator.php#L99-L131
train
eloquent/phony
src/Matcher/MatcherVerifier.php
MatcherVerifier.matches
public function matches(array $matchers, array $arguments): bool { $argumentCount = count($arguments); $index = 0; foreach ($matchers as $matcher) { if ($matcher instanceof WildcardMatcher) { $matchCount = 0; $innerMatcher = $matcher->matcher(); while ( $index < $argumentCount && $innerMatcher->matches($arguments[$index]) ) { ++$matchCount; ++$index; } $maximumArguments = $matcher->maximumArguments(); $isMatch = ( $maximumArguments < 0 || $matchCount <= $maximumArguments ) && $matchCount >= $matcher->minimumArguments(); if (!$isMatch) { return false; } continue; } if ( $index >= $argumentCount || !$matcher->matches($arguments[$index]) ) { return false; } ++$index; } return $index === $argumentCount; }
php
public function matches(array $matchers, array $arguments): bool { $argumentCount = count($arguments); $index = 0; foreach ($matchers as $matcher) { if ($matcher instanceof WildcardMatcher) { $matchCount = 0; $innerMatcher = $matcher->matcher(); while ( $index < $argumentCount && $innerMatcher->matches($arguments[$index]) ) { ++$matchCount; ++$index; } $maximumArguments = $matcher->maximumArguments(); $isMatch = ( $maximumArguments < 0 || $matchCount <= $maximumArguments ) && $matchCount >= $matcher->minimumArguments(); if (!$isMatch) { return false; } continue; } if ( $index >= $argumentCount || !$matcher->matches($arguments[$index]) ) { return false; } ++$index; } return $index === $argumentCount; }
[ "public", "function", "matches", "(", "array", "$", "matchers", ",", "array", "$", "arguments", ")", ":", "bool", "{", "$", "argumentCount", "=", "count", "(", "$", "arguments", ")", ";", "$", "index", "=", "0", ";", "foreach", "(", "$", "matchers", ...
Verify that the supplied arguments match the supplied matchers. @param array<Matchable> $matchers The matchers. @param array $arguments The arguments. @return bool True if the arguments match.
[ "Verify", "that", "the", "supplied", "arguments", "match", "the", "supplied", "matchers", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherVerifier.php#L34-L79
train
eloquent/phony
src/Matcher/MatcherVerifier.php
MatcherVerifier.explain
public function explain(array $matchers, array $arguments): MatcherResult { $isMatch = true; $matcherMatches = []; $argumentMatches = []; $argumentCount = count($arguments); $index = 0; foreach ($matchers as $matcher) { if ($matcher instanceof WildcardMatcher) { $matcherIsMatch = true; $innerMatcher = $matcher->matcher(); $minimumArguments = $matcher->minimumArguments(); $maximumArguments = $matcher->maximumArguments(); for ($count = 0; $count < $minimumArguments; ++$count) { if ($index >= $argumentCount) { $matcherIsMatch = false; $argumentMatches[] = false; break; } if ($innerMatcher->matches($arguments[$index])) { $argumentMatches[] = true; } else { $matcherIsMatch = false; $argumentMatches[] = false; } ++$index; } if ($maximumArguments < 0) { while ( $index < $argumentCount && $innerMatcher->matches($arguments[$index]) ) { $argumentMatches[] = true; ++$index; } } else { for (; $count < $maximumArguments; ++$count) { if ( $index >= $argumentCount || !$innerMatcher->matches($arguments[$index]) ) { break; } $argumentMatches[] = true; ++$index; } } $isMatch = $isMatch && $matcherIsMatch; $matcherMatches[] = $matcherIsMatch; continue; } $matcherIsMatch = $index < $argumentCount && $matcher->matches($arguments[$index]); $isMatch = $isMatch && $matcherIsMatch; $matcherMatches[] = $matcherIsMatch; $argumentMatches[] = $matcherIsMatch; ++$index; } for (; $index < $argumentCount; ++$index) { $argumentMatches[] = false; $isMatch = false; } return new MatcherResult($isMatch, $matcherMatches, $argumentMatches); }
php
public function explain(array $matchers, array $arguments): MatcherResult { $isMatch = true; $matcherMatches = []; $argumentMatches = []; $argumentCount = count($arguments); $index = 0; foreach ($matchers as $matcher) { if ($matcher instanceof WildcardMatcher) { $matcherIsMatch = true; $innerMatcher = $matcher->matcher(); $minimumArguments = $matcher->minimumArguments(); $maximumArguments = $matcher->maximumArguments(); for ($count = 0; $count < $minimumArguments; ++$count) { if ($index >= $argumentCount) { $matcherIsMatch = false; $argumentMatches[] = false; break; } if ($innerMatcher->matches($arguments[$index])) { $argumentMatches[] = true; } else { $matcherIsMatch = false; $argumentMatches[] = false; } ++$index; } if ($maximumArguments < 0) { while ( $index < $argumentCount && $innerMatcher->matches($arguments[$index]) ) { $argumentMatches[] = true; ++$index; } } else { for (; $count < $maximumArguments; ++$count) { if ( $index >= $argumentCount || !$innerMatcher->matches($arguments[$index]) ) { break; } $argumentMatches[] = true; ++$index; } } $isMatch = $isMatch && $matcherIsMatch; $matcherMatches[] = $matcherIsMatch; continue; } $matcherIsMatch = $index < $argumentCount && $matcher->matches($arguments[$index]); $isMatch = $isMatch && $matcherIsMatch; $matcherMatches[] = $matcherIsMatch; $argumentMatches[] = $matcherIsMatch; ++$index; } for (; $index < $argumentCount; ++$index) { $argumentMatches[] = false; $isMatch = false; } return new MatcherResult($isMatch, $matcherMatches, $argumentMatches); }
[ "public", "function", "explain", "(", "array", "$", "matchers", ",", "array", "$", "arguments", ")", ":", "MatcherResult", "{", "$", "isMatch", "=", "true", ";", "$", "matcherMatches", "=", "[", "]", ";", "$", "argumentMatches", "=", "[", "]", ";", "$"...
Explain which of the supplied arguments match which of the supplied matchers. @param array<Matchable> $matchers The matchers. @param array $arguments The arguments. @return MatcherResult The result of matching.
[ "Explain", "which", "of", "the", "supplied", "arguments", "match", "which", "of", "the", "supplied", "matchers", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherVerifier.php#L90-L167
train
eloquent/phony
src/Exporter/InlineExporter.php
InlineExporter.instance
public static function instance(): self { if (!self::$instance) { self::$instance = new self( 1, Sequencer::sequence('exporter-object-id'), InvocableInspector::instance() ); } return self::$instance; }
php
public static function instance(): self { if (!self::$instance) { self::$instance = new self( 1, Sequencer::sequence('exporter-object-id'), InvocableInspector::instance() ); } return self::$instance; }
[ "public", "static", "function", "instance", "(", ")", ":", "self", "{", "if", "(", "!", "self", "::", "$", "instance", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", "1", ",", "Sequencer", "::", "sequence", "(", "'exporter-object-id'...
Get the static instance of this exporter. @return Exporter The static exporter.
[ "Get", "the", "static", "instance", "of", "this", "exporter", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Exporter/InlineExporter.php#L38-L49
train
eloquent/phony
src/Exporter/InlineExporter.php
InlineExporter.setDepth
public function setDepth(int $depth): int { $oldDepth = $this->depth; $this->depth = $depth; return $oldDepth; }
php
public function setDepth(int $depth): int { $oldDepth = $this->depth; $this->depth = $depth; return $oldDepth; }
[ "public", "function", "setDepth", "(", "int", "$", "depth", ")", ":", "int", "{", "$", "oldDepth", "=", "$", "this", "->", "depth", ";", "$", "this", "->", "depth", "=", "$", "depth", ";", "return", "$", "oldDepth", ";", "}" ]
Set the default depth. Negative depths are treated as infinite depth. @param int $depth The depth. @return int The previous depth.
[ "Set", "the", "default", "depth", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Exporter/InlineExporter.php#L86-L92
train
eloquent/phony
src/Exporter/InlineExporter.php
InlineExporter.exportCallable
public function exportCallable($callback): string { $wrappedCallback = null; while ($callback instanceof WrappedInvocable) { $wrappedCallback = $callback; $callback = $callback->callback(); } $label = ''; if ($wrappedCallback) { if ($wrappedCallback->isAnonymous()) { return $this->export($wrappedCallback); } $label = $wrappedCallback->label(); if ('' !== $label) { $label = '[' . $label . ']'; } } if ($callback instanceof Closure) { return $this->export($callback) . $label; } $reflector = $this->invocableInspector->callbackReflector($callback); if (!$reflector instanceof ReflectionMethod) { return $reflector->getName() . $label; } $class = $reflector->getDeclaringClass(); $name = $reflector->getName(); if ($class->implementsInterface(Mock::class)) { if ( ($parentClass = $class->getParentClass()) && $parentClass->hasMethod($name) ) { $class = $parentClass; } else { try { $prototype = $reflector->getPrototype(); $class = $prototype->getDeclaringClass(); } catch (ReflectionException $e) { // ignore } } } $atoms = explode('\\', $class->getName()); $rendered = array_pop($atoms); if ($wrappedCallback instanceof WrappedMethod) { $name = $wrappedCallback->name(); $handle = $wrappedCallback->handle(); if ($handle instanceof InstanceHandle) { $label = $handle->label(); if ('' !== $label) { $rendered .= '[' . $label . ']'; } } } if ($reflector->isStatic()) { $callOperator = '::'; } else { $callOperator = '->'; } return $rendered . $callOperator . $name; }
php
public function exportCallable($callback): string { $wrappedCallback = null; while ($callback instanceof WrappedInvocable) { $wrappedCallback = $callback; $callback = $callback->callback(); } $label = ''; if ($wrappedCallback) { if ($wrappedCallback->isAnonymous()) { return $this->export($wrappedCallback); } $label = $wrappedCallback->label(); if ('' !== $label) { $label = '[' . $label . ']'; } } if ($callback instanceof Closure) { return $this->export($callback) . $label; } $reflector = $this->invocableInspector->callbackReflector($callback); if (!$reflector instanceof ReflectionMethod) { return $reflector->getName() . $label; } $class = $reflector->getDeclaringClass(); $name = $reflector->getName(); if ($class->implementsInterface(Mock::class)) { if ( ($parentClass = $class->getParentClass()) && $parentClass->hasMethod($name) ) { $class = $parentClass; } else { try { $prototype = $reflector->getPrototype(); $class = $prototype->getDeclaringClass(); } catch (ReflectionException $e) { // ignore } } } $atoms = explode('\\', $class->getName()); $rendered = array_pop($atoms); if ($wrappedCallback instanceof WrappedMethod) { $name = $wrappedCallback->name(); $handle = $wrappedCallback->handle(); if ($handle instanceof InstanceHandle) { $label = $handle->label(); if ('' !== $label) { $rendered .= '[' . $label . ']'; } } } if ($reflector->isStatic()) { $callOperator = '::'; } else { $callOperator = '->'; } return $rendered . $callOperator . $name; }
[ "public", "function", "exportCallable", "(", "$", "callback", ")", ":", "string", "{", "$", "wrappedCallback", "=", "null", ";", "while", "(", "$", "callback", "instanceof", "WrappedInvocable", ")", "{", "$", "wrappedCallback", "=", "$", "callback", ";", "$"...
Export a string representation of a callable value. @param callable $callback The callable. @return string The exported callable.
[ "Export", "a", "string", "representation", "of", "a", "callable", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Exporter/InlineExporter.php#L642-L717
train
eloquent/phony
src/Stub/StubData.php
StubData.with
public function with(...$arguments): Stub { $this->closeRule(); if (empty($this->rules)) { $defaultAnswerCallback = $this->defaultAnswerCallback; $defaultAnswerCallback($this); $this->closeRule(); } $this->criteria = $this->matcherFactory->adaptAll($arguments); return $this; }
php
public function with(...$arguments): Stub { $this->closeRule(); if (empty($this->rules)) { $defaultAnswerCallback = $this->defaultAnswerCallback; $defaultAnswerCallback($this); $this->closeRule(); } $this->criteria = $this->matcherFactory->adaptAll($arguments); return $this; }
[ "public", "function", "with", "(", "...", "$", "arguments", ")", ":", "Stub", "{", "$", "this", "->", "closeRule", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "rules", ")", ")", "{", "$", "defaultAnswerCallback", "=", "$", "this", "-...
Modify the current criteria to match the supplied arguments. @param mixed ...$arguments The arguments. @return $this This stub.
[ "Modify", "the", "current", "criteria", "to", "match", "the", "supplied", "arguments", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubData.php#L161-L174
train
eloquent/phony
src/Stub/StubData.php
StubData.returns
public function returns(...$values): Stub { if (empty($values)) { $callback = $this->callback; $invocableInspector = $this->invocableInspector; $emptyValueFactory = $this->emptyValueFactory; $value = null; $valueIsSet = false; return $this->doesWith( function () use ( &$value, &$valueIsSet, $callback, $invocableInspector, $emptyValueFactory ) { if (!$valueIsSet) { if ( $type = $invocableInspector ->callbackReturnType($callback) ) { try { $value = $emptyValueFactory->fromType($type); } catch (FinalClassException $e){ throw new FinalReturnTypeException( $this->exporter->exportCallable($callback), strval($type), $e ); } } else { $value = null; } $valueIsSet = true; } return $value; }, [], false, false, false ); } foreach ($values as $value) { if ($value instanceof InstanceHandle) { $value = $value->get(); } $this->doesWith( function () use ($value) { return $value; }, [], false, false, false ); } return $this; }
php
public function returns(...$values): Stub { if (empty($values)) { $callback = $this->callback; $invocableInspector = $this->invocableInspector; $emptyValueFactory = $this->emptyValueFactory; $value = null; $valueIsSet = false; return $this->doesWith( function () use ( &$value, &$valueIsSet, $callback, $invocableInspector, $emptyValueFactory ) { if (!$valueIsSet) { if ( $type = $invocableInspector ->callbackReturnType($callback) ) { try { $value = $emptyValueFactory->fromType($type); } catch (FinalClassException $e){ throw new FinalReturnTypeException( $this->exporter->exportCallable($callback), strval($type), $e ); } } else { $value = null; } $valueIsSet = true; } return $value; }, [], false, false, false ); } foreach ($values as $value) { if ($value instanceof InstanceHandle) { $value = $value->get(); } $this->doesWith( function () use ($value) { return $value; }, [], false, false, false ); } return $this; }
[ "public", "function", "returns", "(", "...", "$", "values", ")", ":", "Stub", "{", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "$", "callback", "=", "$", "this", "->", "callback", ";", "$", "invocableInspector", "=", "$", "this", "->", "...
Add an answer that returns a value. Calling this method with no arguments is equivalent to calling it with a single argument of `null`. @param mixed ...$values The return values. @return $this This stub.
[ "Add", "an", "answer", "that", "returns", "a", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubData.php#L497-L562
train
eloquent/phony
src/Stub/StubData.php
StubData.returnsArgument
public function returnsArgument(int $index = 0): Stub { return $this->doesWith( function ($arguments) use ($index) { return $arguments->get($index); }, [], false, true, false ); }
php
public function returnsArgument(int $index = 0): Stub { return $this->doesWith( function ($arguments) use ($index) { return $arguments->get($index); }, [], false, true, false ); }
[ "public", "function", "returnsArgument", "(", "int", "$", "index", "=", "0", ")", ":", "Stub", "{", "return", "$", "this", "->", "doesWith", "(", "function", "(", "$", "arguments", ")", "use", "(", "$", "index", ")", "{", "return", "$", "arguments", ...
Add an answer that returns an argument. Negative indices are offset from the end of the list. That is, `-1` indicates the last element, and `-2` indicates the second last element. @param int $index The argument index. @return $this This stub.
[ "Add", "an", "answer", "that", "returns", "an", "argument", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubData.php#L574-L585
train
eloquent/phony
src/Stub/StubData.php
StubData.throws
public function throws(...$exceptions): Stub { if (empty($exceptions)) { return $this->doesWith( function () { throw new Exception(); }, [], false, false, false ); } foreach ($exceptions as $exception) { if (is_string($exception)) { $exception = new Exception($exception); } elseif ($exception instanceof InstanceHandle) { $exception = $exception->get(); } $this->doesWith( function () use ($exception) { throw $exception; }, [], false, false, false ); } return $this; }
php
public function throws(...$exceptions): Stub { if (empty($exceptions)) { return $this->doesWith( function () { throw new Exception(); }, [], false, false, false ); } foreach ($exceptions as $exception) { if (is_string($exception)) { $exception = new Exception($exception); } elseif ($exception instanceof InstanceHandle) { $exception = $exception->get(); } $this->doesWith( function () use ($exception) { throw $exception; }, [], false, false, false ); } return $this; }
[ "public", "function", "throws", "(", "...", "$", "exceptions", ")", ":", "Stub", "{", "if", "(", "empty", "(", "$", "exceptions", ")", ")", "{", "return", "$", "this", "->", "doesWith", "(", "function", "(", ")", "{", "throw", "new", "Exception", "("...
Add an answer that throws an exception. Calling this method with no arguments is equivalent to calling it with a single argument of `null`. @param Throwable|string|null ...$exceptions The exceptions, or messages, or nulls to throw generic exceptions. @return $this This stub.
[ "Add", "an", "answer", "that", "throws", "an", "exception", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubData.php#L615-L648
train
eloquent/phony
src/Stub/StubData.php
StubData.generates
public function generates(...$values): GeneratorAnswerBuilder { $builder = $this->generatorAnswerBuilderFactory->create($this); $this->doesWith($builder->answer(), [], true, true, false); foreach ($values as $index => $subValues) { if ($index > 0) { $builder->returns(); $builder = $this->generatorAnswerBuilderFactory->create($this); $this->doesWith($builder->answer(), [], true, true, false); } $builder->yieldsFrom($subValues); } return $builder; }
php
public function generates(...$values): GeneratorAnswerBuilder { $builder = $this->generatorAnswerBuilderFactory->create($this); $this->doesWith($builder->answer(), [], true, true, false); foreach ($values as $index => $subValues) { if ($index > 0) { $builder->returns(); $builder = $this->generatorAnswerBuilderFactory->create($this); $this->doesWith($builder->answer(), [], true, true, false); } $builder->yieldsFrom($subValues); } return $builder; }
[ "public", "function", "generates", "(", "...", "$", "values", ")", ":", "GeneratorAnswerBuilder", "{", "$", "builder", "=", "$", "this", "->", "generatorAnswerBuilderFactory", "->", "create", "(", "$", "this", ")", ";", "$", "this", "->", "doesWith", "(", ...
Add an answer that returns a generator, and return a builder for customizing the generator's behavior. @param mixed<mixed,mixed> ...$values Sets of keys and values to yield. @return GeneratorAnswerBuilder The answer builder.
[ "Add", "an", "answer", "that", "returns", "a", "generator", "and", "return", "a", "builder", "for", "customizing", "the", "generator", "s", "behavior", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubData.php#L658-L675
train
eloquent/phony
src/Stub/StubData.php
StubData.closeRule
public function closeRule(): Stub { if (!empty($this->secondaryRequests)) { $defaultAnswerCallback = $this->defaultAnswerCallback; $defaultAnswerCallback($this); $this->secondaryRequests = []; } if (!empty($this->answers)) { if (null !== $this->criteria) { $rule = new StubRule($this->criteria, $this->answers); $this->criteria = null; } else { $rule = new StubRule( [$this->matcherFactory->wildcard()], $this->answers ); } array_unshift($this->rules, $rule); $this->answers = []; } if (null !== $this->criteria) { $criteria = $this->criteria; $this->criteria = null; throw new UnusedStubCriteriaException($criteria); } return $this; }
php
public function closeRule(): Stub { if (!empty($this->secondaryRequests)) { $defaultAnswerCallback = $this->defaultAnswerCallback; $defaultAnswerCallback($this); $this->secondaryRequests = []; } if (!empty($this->answers)) { if (null !== $this->criteria) { $rule = new StubRule($this->criteria, $this->answers); $this->criteria = null; } else { $rule = new StubRule( [$this->matcherFactory->wildcard()], $this->answers ); } array_unshift($this->rules, $rule); $this->answers = []; } if (null !== $this->criteria) { $criteria = $this->criteria; $this->criteria = null; throw new UnusedStubCriteriaException($criteria); } return $this; }
[ "public", "function", "closeRule", "(", ")", ":", "Stub", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "secondaryRequests", ")", ")", "{", "$", "defaultAnswerCallback", "=", "$", "this", "->", "defaultAnswerCallback", ";", "$", "defaultAnswerCallbac...
Close any existing rule. @return $this This stub.
[ "Close", "any", "existing", "rule", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubData.php#L682-L714
train
eloquent/phony
src/Hook/FunctionHookManager.php
FunctionHookManager.instance
public static function instance(): self { if (!self::$instance) { self::$instance = new self( InvocableInspector::instance(), FunctionSignatureInspector::instance(), FunctionHookGenerator::instance() ); } return self::$instance; }
php
public static function instance(): self { if (!self::$instance) { self::$instance = new self( InvocableInspector::instance(), FunctionSignatureInspector::instance(), FunctionHookGenerator::instance() ); } return self::$instance; }
[ "public", "static", "function", "instance", "(", ")", ":", "self", "{", "if", "(", "!", "self", "::", "$", "instance", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", "InvocableInspector", "::", "instance", "(", ")", ",", "FunctionSig...
Get the static instance of this manager. @return FunctionHookManager The static manager.
[ "Get", "the", "static", "instance", "of", "this", "manager", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Hook/FunctionHookManager.php#L25-L36
train
eloquent/phony
src/Hook/FunctionHookManager.php
FunctionHookManager.defineFunction
public function defineFunction( string $name, string $namespace, $callback ) { $signature = $this->signatureInspector->signature( $this->invocableInspector->callbackReflector($callback) ); $fullName = $namespace . '\\' . $name; $key = strtolower($fullName); if (isset(self::$hooks[$key])) { if ($signature !== self::$hooks[$key]['signature']) { throw new FunctionSignatureMismatchException($fullName); } $replaced = self::$hooks[$key]['callback']; } else { $replaced = null; if (function_exists($fullName)) { throw new FunctionExistsException($fullName); } $source = $this->hookGenerator ->generateHook($name, $namespace, $signature); $reporting = error_reporting(E_ERROR | E_COMPILE_ERROR); try { eval($source); } catch (ParseError $e) { throw new FunctionHookGenerationFailedException( $fullName, $callback, $source, error_get_last(), $e ); } finally { error_reporting($reporting); } if (!function_exists($fullName)) { // @codeCoverageIgnoreStart throw new FunctionHookGenerationFailedException( $fullName, $callback, $source, error_get_last() ); // @codeCoverageIgnoreEnd } } self::$hooks[$key] = ['callback' => $callback, 'signature' => $signature]; return $replaced; }
php
public function defineFunction( string $name, string $namespace, $callback ) { $signature = $this->signatureInspector->signature( $this->invocableInspector->callbackReflector($callback) ); $fullName = $namespace . '\\' . $name; $key = strtolower($fullName); if (isset(self::$hooks[$key])) { if ($signature !== self::$hooks[$key]['signature']) { throw new FunctionSignatureMismatchException($fullName); } $replaced = self::$hooks[$key]['callback']; } else { $replaced = null; if (function_exists($fullName)) { throw new FunctionExistsException($fullName); } $source = $this->hookGenerator ->generateHook($name, $namespace, $signature); $reporting = error_reporting(E_ERROR | E_COMPILE_ERROR); try { eval($source); } catch (ParseError $e) { throw new FunctionHookGenerationFailedException( $fullName, $callback, $source, error_get_last(), $e ); } finally { error_reporting($reporting); } if (!function_exists($fullName)) { // @codeCoverageIgnoreStart throw new FunctionHookGenerationFailedException( $fullName, $callback, $source, error_get_last() ); // @codeCoverageIgnoreEnd } } self::$hooks[$key] = ['callback' => $callback, 'signature' => $signature]; return $replaced; }
[ "public", "function", "defineFunction", "(", "string", "$", "name", ",", "string", "$", "namespace", ",", "$", "callback", ")", "{", "$", "signature", "=", "$", "this", "->", "signatureInspector", "->", "signature", "(", "$", "this", "->", "invocableInspecto...
Define the behavior of a function hook. @param string $name The function name. @param string $namespace The namespace. @param callable $callback The callback. @return callable|null The replaced callback, or null if no callback was set. @throws FunctionHookException If the function hook generation fails.
[ "Define", "the", "behavior", "of", "a", "function", "hook", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Hook/FunctionHookManager.php#L65-L123
train
eloquent/phony
src/Hook/FunctionHookManager.php
FunctionHookManager.restoreGlobalFunctions
public function restoreGlobalFunctions(): void { foreach (self::$hooks as $key => $data) { self::$hooks[$key]['callback'] = null; } }
php
public function restoreGlobalFunctions(): void { foreach (self::$hooks as $key => $data) { self::$hooks[$key]['callback'] = null; } }
[ "public", "function", "restoreGlobalFunctions", "(", ")", ":", "void", "{", "foreach", "(", "self", "::", "$", "hooks", "as", "$", "key", "=>", "$", "data", ")", "{", "self", "::", "$", "hooks", "[", "$", "key", "]", "[", "'callback'", "]", "=", "n...
Effectively removes any function hooks for functions in the global namespace.
[ "Effectively", "removes", "any", "function", "hooks", "for", "functions", "in", "the", "global", "namespace", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Hook/FunctionHookManager.php#L129-L134
train
eloquent/phony
src/Stub/StubVerifier.php
StubVerifier.setsArgument
public function setsArgument($indexOrValue = null, $value = null): Stub { if (func_num_args() > 1) { $this->stub->setsArgument($indexOrValue, $value); } else { $this->stub->setsArgument($indexOrValue); } return $this; }
php
public function setsArgument($indexOrValue = null, $value = null): Stub { if (func_num_args() > 1) { $this->stub->setsArgument($indexOrValue, $value); } else { $this->stub->setsArgument($indexOrValue); } return $this; }
[ "public", "function", "setsArgument", "(", "$", "indexOrValue", "=", "null", ",", "$", "value", "=", "null", ")", ":", "Stub", "{", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "{", "$", "this", "->", "stub", "->", "setsArgument", "(", "$", ...
Set the value of an argument passed by reference as part of an answer. If called with no arguments, sets the first argument to null. If called with one argument, sets the first argument to $indexOrValue. If called with two arguments, sets the argument at $indexOrValue to $value. @param mixed $indexOrValue The index, or value if no index is specified. @param mixed $value The value. @return $this This stub.
[ "Set", "the", "value", "of", "an", "argument", "passed", "by", "reference", "as", "part", "of", "an", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifier.php#L286-L295
train
eloquent/phony
src/Difference/DifferenceSequenceMatcher.php
DifferenceSequenceMatcher.tupleSort
private function tupleSort($a, $b) { $aLength = count($a); $bLength = count($b); if ($aLength > $bLength) { $max = $aLength; } else { $max = $bLength; } for ($i = 0; $i < $max; ++$i) { if ($a[$i] < $b[$i]) { return -1; } if ($a[$i] > $b[$i]) { return 1; } } return $aLength <=> $bLength; }
php
private function tupleSort($a, $b) { $aLength = count($a); $bLength = count($b); if ($aLength > $bLength) { $max = $aLength; } else { $max = $bLength; } for ($i = 0; $i < $max; ++$i) { if ($a[$i] < $b[$i]) { return -1; } if ($a[$i] > $b[$i]) { return 1; } } return $aLength <=> $bLength; }
[ "private", "function", "tupleSort", "(", "$", "a", ",", "$", "b", ")", "{", "$", "aLength", "=", "count", "(", "$", "a", ")", ";", "$", "bLength", "=", "count", "(", "$", "b", ")", ";", "if", "(", "$", "aLength", ">", "$", "bLength", ")", "{"...
Sort an array by the nested arrays it contains. Helper function for getMatchingBlocks. @param array $a First array to compare. @param array $b Second array to compare. @return int -1, 0 or 1, as expected by the usort function.
[ "Sort", "an", "array", "by", "the", "nested", "arrays", "it", "contains", ".", "Helper", "function", "for", "getMatchingBlocks", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Difference/DifferenceSequenceMatcher.php#L326-L348
train
eloquent/phony
src/Verification/Cardinality.php
Cardinality.setIsAlways
public function setIsAlways(bool $isAlways): void { if ($isAlways && $this->isNever()) { throw new InvalidCardinalityStateException(); } $this->isAlways = $isAlways; }
php
public function setIsAlways(bool $isAlways): void { if ($isAlways && $this->isNever()) { throw new InvalidCardinalityStateException(); } $this->isAlways = $isAlways; }
[ "public", "function", "setIsAlways", "(", "bool", "$", "isAlways", ")", ":", "void", "{", "if", "(", "$", "isAlways", "&&", "$", "this", "->", "isNever", "(", ")", ")", "{", "throw", "new", "InvalidCardinalityStateException", "(", ")", ";", "}", "$", "...
Turn 'always' on or off. @param bool $isAlways True to enable 'always'. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Turn", "always", "on", "or", "off", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/Cardinality.php#L86-L93
train
eloquent/phony
src/Verification/Cardinality.php
Cardinality.matches
public function matches($count, int $maximumCount): bool { $count = intval($count); $result = true; if ($count < $this->minimum) { $result = false; } if ($this->maximum >= 0 && $count > $this->maximum) { $result = false; } if ($this->isAlways && $count < $maximumCount) { $result = false; } return $result; }
php
public function matches($count, int $maximumCount): bool { $count = intval($count); $result = true; if ($count < $this->minimum) { $result = false; } if ($this->maximum >= 0 && $count > $this->maximum) { $result = false; } if ($this->isAlways && $count < $maximumCount) { $result = false; } return $result; }
[ "public", "function", "matches", "(", "$", "count", ",", "int", "$", "maximumCount", ")", ":", "bool", "{", "$", "count", "=", "intval", "(", "$", "count", ")", ";", "$", "result", "=", "true", ";", "if", "(", "$", "count", "<", "$", "this", "->"...
Returns true if the supplied count matches this cardinality. @param int|bool $count The count or result to check. @param int $maximumCount The maximum possible count. @return bool True if the supplied count matches this cardinality.
[ "Returns", "true", "if", "the", "supplied", "count", "matches", "this", "cardinality", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/Cardinality.php#L113-L131
train
eloquent/phony
src/Verification/Cardinality.php
Cardinality.assertSingular
public function assertSingular(): self { if ($this->minimum > 1 || $this->maximum > 1 || $this->isAlways) { throw new InvalidSingularCardinalityException($this); } return $this; }
php
public function assertSingular(): self { if ($this->minimum > 1 || $this->maximum > 1 || $this->isAlways) { throw new InvalidSingularCardinalityException($this); } return $this; }
[ "public", "function", "assertSingular", "(", ")", ":", "self", "{", "if", "(", "$", "this", "->", "minimum", ">", "1", "||", "$", "this", "->", "maximum", ">", "1", "||", "$", "this", "->", "isAlways", ")", "{", "throw", "new", "InvalidSingularCardinal...
Asserts that this cardinality is suitable for events that can only happen once or not at all. @return $this This cardinality. @throws InvalidCardinalityException If the cardinality is invalid.
[ "Asserts", "that", "this", "cardinality", "is", "suitable", "for", "events", "that", "can", "only", "happen", "once", "or", "not", "at", "all", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/Cardinality.php#L140-L147
train
chadicus/slim-oauth2-routes
src/UserIdProvider.php
UserIdProvider.getUserId
public function getUserId(ServerRequestInterface $request, array $arguments = []) { $queryParams = $request->getQueryParams(); return array_key_exists('user_id', $queryParams) ? $queryParams['user_id'] : null; }
php
public function getUserId(ServerRequestInterface $request, array $arguments = []) { $queryParams = $request->getQueryParams(); return array_key_exists('user_id', $queryParams) ? $queryParams['user_id'] : null; }
[ "public", "function", "getUserId", "(", "ServerRequestInterface", "$", "request", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "$", "queryParams", "=", "$", "request", "->", "getQueryParams", "(", ")", ";", "return", "array_key_exists", "(", "'us...
Extracts a user_id from the given HTTP request query params. @param ServerRequestInterface $request The incoming HTTP request. @param array $arguments Any route parameters associated with the request. @return string|null The user id if it exists, otherwise null
[ "Extracts", "a", "user_id", "from", "the", "given", "HTTP", "request", "query", "params", "." ]
d69d4e32102651de044860b38e686c9759150d7f
https://github.com/chadicus/slim-oauth2-routes/blob/d69d4e32102651de044860b38e686c9759150d7f/src/UserIdProvider.php#L20-L24
train
eloquent/phony
src/Mock/MockFactory.php
MockFactory.createMockClass
public function createMockClass( MockDefinition $definition, bool $createNew = false ): ReflectionClass { $signature = $definition->signature(); if (!$createNew) { foreach ($this->definitions as $tuple) { if ($signature === $tuple[0]) { return $tuple[1]; } } } $className = $this->generator->generateClassName($definition); if (class_exists($className, false)) { throw new ClassExistsException($className); } $source = $this->generator->generate($definition, $className); $reporting = error_reporting(E_ERROR | E_COMPILE_ERROR); try { eval($source); } catch (ParseError $e) { throw new MockGenerationFailedException( $className, $definition, $source, error_get_last(), $e ); } finally { error_reporting($reporting); } if (!class_exists($className, false)) { // @codeCoverageIgnoreStart throw new MockGenerationFailedException( $className, $definition, $source, error_get_last() ); // @codeCoverageIgnoreEnd } $class = new ReflectionClass($className); $customMethods = []; foreach ($definition->customStaticMethods() as $methodName => $method) { $customMethods[strtolower($methodName)] = $method[0]; } foreach ($definition->customMethods() as $methodName => $method) { $customMethods[strtolower($methodName)] = $method[0]; } $customMethodsProperty = $class->getProperty('_customMethods'); $customMethodsProperty->setAccessible(true); $customMethodsProperty->setValue(null, $customMethods); $this->handleFactory->staticHandle($class); $this->definitions[] = [$signature, $class]; return $class; }
php
public function createMockClass( MockDefinition $definition, bool $createNew = false ): ReflectionClass { $signature = $definition->signature(); if (!$createNew) { foreach ($this->definitions as $tuple) { if ($signature === $tuple[0]) { return $tuple[1]; } } } $className = $this->generator->generateClassName($definition); if (class_exists($className, false)) { throw new ClassExistsException($className); } $source = $this->generator->generate($definition, $className); $reporting = error_reporting(E_ERROR | E_COMPILE_ERROR); try { eval($source); } catch (ParseError $e) { throw new MockGenerationFailedException( $className, $definition, $source, error_get_last(), $e ); } finally { error_reporting($reporting); } if (!class_exists($className, false)) { // @codeCoverageIgnoreStart throw new MockGenerationFailedException( $className, $definition, $source, error_get_last() ); // @codeCoverageIgnoreEnd } $class = new ReflectionClass($className); $customMethods = []; foreach ($definition->customStaticMethods() as $methodName => $method) { $customMethods[strtolower($methodName)] = $method[0]; } foreach ($definition->customMethods() as $methodName => $method) { $customMethods[strtolower($methodName)] = $method[0]; } $customMethodsProperty = $class->getProperty('_customMethods'); $customMethodsProperty->setAccessible(true); $customMethodsProperty->setValue(null, $customMethods); $this->handleFactory->staticHandle($class); $this->definitions[] = [$signature, $class]; return $class; }
[ "public", "function", "createMockClass", "(", "MockDefinition", "$", "definition", ",", "bool", "$", "createNew", "=", "false", ")", ":", "ReflectionClass", "{", "$", "signature", "=", "$", "definition", "->", "signature", "(", ")", ";", "if", "(", "!", "$...
Create the mock class for the supplied definition. @param MockDefinition $definition The definition. @param bool $createNew True if a new class should be created even when a compatible one exists. @return ReflectionClass The class. @throws MockException If the mock generation fails.
[ "Create", "the", "mock", "class", "for", "the", "supplied", "definition", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockFactory.php#L67-L134
train
eloquent/phony
src/Mock/MockFactory.php
MockFactory.createFullMock
public function createFullMock(ReflectionClass $class): Mock { $mock = $class->newInstanceWithoutConstructor(); $this->handleFactory ->instanceHandle($mock, strval($this->labelSequencer->next())); return $mock; }
php
public function createFullMock(ReflectionClass $class): Mock { $mock = $class->newInstanceWithoutConstructor(); $this->handleFactory ->instanceHandle($mock, strval($this->labelSequencer->next())); return $mock; }
[ "public", "function", "createFullMock", "(", "ReflectionClass", "$", "class", ")", ":", "Mock", "{", "$", "mock", "=", "$", "class", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "this", "->", "handleFactory", "->", "instanceHandle", "(", "$", "...
Create a new full mock instance for the supplied class. @param ReflectionClass $class The class. @return Mock The newly created mock. @throws MockException If the mock generation fails.
[ "Create", "a", "new", "full", "mock", "instance", "for", "the", "supplied", "class", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockFactory.php#L144-L151
train
eloquent/phony
src/Mock/MockFactory.php
MockFactory.createPartialMock
public function createPartialMock( ReflectionClass $class, $arguments = [] ): Mock { $mock = $class->newInstanceWithoutConstructor(); $handle = $this->handleFactory ->instanceHandle($mock, strval($this->labelSequencer->next())); $handle->partial(); if (null !== $arguments) { $handle->constructWith($arguments); } return $mock; }
php
public function createPartialMock( ReflectionClass $class, $arguments = [] ): Mock { $mock = $class->newInstanceWithoutConstructor(); $handle = $this->handleFactory ->instanceHandle($mock, strval($this->labelSequencer->next())); $handle->partial(); if (null !== $arguments) { $handle->constructWith($arguments); } return $mock; }
[ "public", "function", "createPartialMock", "(", "ReflectionClass", "$", "class", ",", "$", "arguments", "=", "[", "]", ")", ":", "Mock", "{", "$", "mock", "=", "$", "class", "->", "newInstanceWithoutConstructor", "(", ")", ";", "$", "handle", "=", "$", "...
Create a new partial mock instance for the supplied definition. @param ReflectionClass $class The class. @param Arguments|array|null $arguments The constructor arguments, or null to bypass the constructor. @return Mock The newly created mock. @throws MockException If the mock generation fails.
[ "Create", "a", "new", "partial", "mock", "instance", "for", "the", "supplied", "definition", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockFactory.php#L162-L176
train
eloquent/phony
src/Stub/EmptyValueFactory.php
EmptyValueFactory.fromType
public function fromType(ReflectionType $type) { if ($type->allowsNull()) { return null; } $typeName = strval($type); switch (strtolower($typeName)) { case 'bool': return false; case 'int': return 0; case 'float': return .0; case 'string': return ''; case 'array': case 'iterable': return []; case 'object': // @codeCoverageIgnoreStart if (!$this->isObjectTypeSupported) { break; } // @codeCoverageIgnoreEnd // no break case 'stdclass': return (object) []; case 'callable': return $this->stubVerifierFactory->create(); case 'closure': return function () {}; case 'generator': $fn = function () { return; yield; }; return $fn(); case 'void': return null; } return $this->mockBuilderFactory->create($typeName)->full(); }
php
public function fromType(ReflectionType $type) { if ($type->allowsNull()) { return null; } $typeName = strval($type); switch (strtolower($typeName)) { case 'bool': return false; case 'int': return 0; case 'float': return .0; case 'string': return ''; case 'array': case 'iterable': return []; case 'object': // @codeCoverageIgnoreStart if (!$this->isObjectTypeSupported) { break; } // @codeCoverageIgnoreEnd // no break case 'stdclass': return (object) []; case 'callable': return $this->stubVerifierFactory->create(); case 'closure': return function () {}; case 'generator': $fn = function () { return; yield; }; return $fn(); case 'void': return null; } return $this->mockBuilderFactory->create($typeName)->full(); }
[ "public", "function", "fromType", "(", "ReflectionType", "$", "type", ")", "{", "if", "(", "$", "type", "->", "allowsNull", "(", ")", ")", "{", "return", "null", ";", "}", "$", "typeName", "=", "strval", "(", "$", "type", ")", ";", "switch", "(", "...
Create a value of the supplied type. @param ReflectionType $type The type. @return mixed A value of the supplied type.
[ "Create", "a", "value", "of", "the", "supplied", "type", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/EmptyValueFactory.php#L71-L124
train
eloquent/phony
src/Verification/GeneratorVerifier.php
GeneratorVerifier.checkReceived
public function checkReceived($value = null): ?EventCollection { $cardinality = $this->resetCardinality(); $argumentCount = func_num_args(); if (0 === $argumentCount) { $checkValue = false; } else { $checkValue = true; $value = $this->matcherFactory->adapt($value); } $isCall = $this->subject instanceof Call; $matchingEvents = []; $matchCount = 0; $eventCount = 0; foreach ($this->calls as $call) { $isMatchingCall = false; foreach ($call->iterableEvents() as $event) { if ($event instanceof ReceivedEvent) { ++$eventCount; if (!$checkValue || $value->matches($event->value())) { $matchingEvents[] = $event; $isMatchingCall = true; if ($isCall) { ++$matchCount; } } } } if (!$isCall && $isMatchingCall) { ++$matchCount; } } if ($isCall) { $totalCount = $eventCount; } else { $totalCount = $this->callCount; } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkReceived($value = null): ?EventCollection { $cardinality = $this->resetCardinality(); $argumentCount = func_num_args(); if (0 === $argumentCount) { $checkValue = false; } else { $checkValue = true; $value = $this->matcherFactory->adapt($value); } $isCall = $this->subject instanceof Call; $matchingEvents = []; $matchCount = 0; $eventCount = 0; foreach ($this->calls as $call) { $isMatchingCall = false; foreach ($call->iterableEvents() as $event) { if ($event instanceof ReceivedEvent) { ++$eventCount; if (!$checkValue || $value->matches($event->value())) { $matchingEvents[] = $event; $isMatchingCall = true; if ($isCall) { ++$matchCount; } } } } if (!$isCall && $isMatchingCall) { ++$matchCount; } } if ($isCall) { $totalCount = $eventCount; } else { $totalCount = $this->callCount; } if ($cardinality->matches($matchCount, $totalCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkReceived", "(", "$", "value", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "$", "argumentCount", "=", "func_num_args", "(", ")", ";", "if", ...
Checks if the subject received the supplied value. When called with no arguments, this method simply checks that the subject received any value. @param mixed $value The value. @return EventCollection|null The result.
[ "Checks", "if", "the", "subject", "received", "the", "supplied", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L66-L117
train
eloquent/phony
src/Verification/GeneratorVerifier.php
GeneratorVerifier.received
public function received($value = null): ?EventCollection { $cardinality = $this->cardinality; $argumentCount = func_num_args(); if (0 === $argumentCount) { $arguments = []; } else { $value = $this->matcherFactory->adapt($value); $arguments = [$value]; } if ($result = $this->checkReceived(...$arguments)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderGeneratorReceived($this->subject, $cardinality, $value) ); }
php
public function received($value = null): ?EventCollection { $cardinality = $this->cardinality; $argumentCount = func_num_args(); if (0 === $argumentCount) { $arguments = []; } else { $value = $this->matcherFactory->adapt($value); $arguments = [$value]; } if ($result = $this->checkReceived(...$arguments)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer ->renderGeneratorReceived($this->subject, $cardinality, $value) ); }
[ "public", "function", "received", "(", "$", "value", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "$", "argumentCount", "=", "func_num_args", "(", ")", ";", "if", "(", "0", "===", "...
Throws an exception unless the subject received the supplied value. When called with no arguments, this method simply checks that the subject received any value. @param mixed $value The value. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "the", "subject", "received", "the", "supplied", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L130-L150
train
eloquent/phony
src/Verification/GeneratorVerifier.php
GeneratorVerifier.receivedException
public function receivedException($type = null): ?EventCollection { $cardinality = $this->cardinality; if ($type instanceof InstanceHandle) { $type = $type->get(); } if ($type instanceof Throwable) { $type = $this->matcherFactory->equalTo($type, true); } elseif ($this->matcherFactory->isMatcher($type)) { $type = $this->matcherFactory->adapt($type); } if ($result = $this->checkReceivedException($type)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderGeneratorReceivedException( $this->subject, $cardinality, $type ) ); }
php
public function receivedException($type = null): ?EventCollection { $cardinality = $this->cardinality; if ($type instanceof InstanceHandle) { $type = $type->get(); } if ($type instanceof Throwable) { $type = $this->matcherFactory->equalTo($type, true); } elseif ($this->matcherFactory->isMatcher($type)) { $type = $this->matcherFactory->adapt($type); } if ($result = $this->checkReceivedException($type)) { return $result; } return $this->assertionRecorder->createFailure( $this->assertionRenderer->renderGeneratorReceivedException( $this->subject, $cardinality, $type ) ); }
[ "public", "function", "receivedException", "(", "$", "type", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "cardinality", ";", "if", "(", "$", "type", "instanceof", "InstanceHandle", ")", "{", "$", "type", ...
Throws an exception unless the subject received an exception of the supplied type. @param Matcher|Throwable|string|null $type An exception to match, the type of exception, or null for any exception. @return EventCollection|null The result, or null if the assertion recorder does not throw exceptions. @throws InvalidArgumentException If the type is invalid. @throws Throwable If the assertion fails, and the assertion recorder throws exceptions.
[ "Throws", "an", "exception", "unless", "the", "subject", "received", "an", "exception", "of", "the", "supplied", "type", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L289-L314
train
eloquent/phony
src/Verification/GeneratorVerifier.php
GeneratorVerifier.checkReturned
public function checkReturned($value = null): ?EventCollection { $cardinality = $this->resetCardinality(); if ($this->subject instanceof Call) { $cardinality->assertSingular(); } $matchingEvents = []; $matchCount = 0; if (0 === func_num_args()) { foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception) = $call->generatorResponse(); if (!$exception) { $matchingEvents[] = $endEvent; ++$matchCount; } } } else { $value = $this->matcherFactory->adapt($value); foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception, $returnValue) = $call->generatorResponse(); if (!$exception && $value->matches($returnValue)) { $matchingEvents[] = $endEvent; ++$matchCount; } } } if ($cardinality->matches($matchCount, $this->callCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkReturned($value = null): ?EventCollection { $cardinality = $this->resetCardinality(); if ($this->subject instanceof Call) { $cardinality->assertSingular(); } $matchingEvents = []; $matchCount = 0; if (0 === func_num_args()) { foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception) = $call->generatorResponse(); if (!$exception) { $matchingEvents[] = $endEvent; ++$matchCount; } } } else { $value = $this->matcherFactory->adapt($value); foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception, $returnValue) = $call->generatorResponse(); if (!$exception && $value->matches($returnValue)) { $matchingEvents[] = $endEvent; ++$matchCount; } } } if ($cardinality->matches($matchCount, $this->callCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkReturned", "(", "$", "value", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "if", "(", "$", "this", "->", "subject", "instanceof", "Call", ")...
Checks if the subject returned the supplied value from a generator. @param mixed $value The value. @return EventCollection|null The result.
[ "Checks", "if", "the", "subject", "returned", "the", "supplied", "value", "from", "a", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L323-L369
train
eloquent/phony
src/Verification/GeneratorVerifier.php
GeneratorVerifier.checkThrew
public function checkThrew($type = null): ?EventCollection { $cardinality = $this->resetCardinality(); if ($this->subject instanceof Call) { $cardinality->assertSingular(); } $matchingEvents = []; $matchCount = 0; $isTypeSupported = false; if (!$type) { $isTypeSupported = true; foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception) = $call->generatorResponse(); if ($exception) { $matchingEvents[] = $endEvent; ++$matchCount; } } } elseif (is_string($type)) { $isTypeSupported = true; foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception) = $call->generatorResponse(); if ($exception && is_a($exception, $type)) { $matchingEvents[] = $endEvent; ++$matchCount; } } } elseif (is_object($type)) { if ($type instanceof InstanceHandle) { $type = $type->get(); } if ($type instanceof Throwable) { $isTypeSupported = true; $type = $this->matcherFactory->equalTo($type, true); } elseif ($this->matcherFactory->isMatcher($type)) { $isTypeSupported = true; $type = $this->matcherFactory->adapt($type); } if ($isTypeSupported) { foreach ($this->calls as $call) { if ( !$call->isGenerator() || !$endEvent = $call->endEvent() ) { continue; } list($exception) = $call->generatorResponse(); if ($exception && $type->matches($exception)) { $matchingEvents[] = $endEvent; ++$matchCount; } } } } if (!$isTypeSupported) { throw new InvalidArgumentException( sprintf( 'Unable to match exceptions against %s.', $this->assertionRenderer->renderValue($type) ) ); } if ($cardinality->matches($matchCount, $this->callCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
php
public function checkThrew($type = null): ?EventCollection { $cardinality = $this->resetCardinality(); if ($this->subject instanceof Call) { $cardinality->assertSingular(); } $matchingEvents = []; $matchCount = 0; $isTypeSupported = false; if (!$type) { $isTypeSupported = true; foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception) = $call->generatorResponse(); if ($exception) { $matchingEvents[] = $endEvent; ++$matchCount; } } } elseif (is_string($type)) { $isTypeSupported = true; foreach ($this->calls as $call) { if (!$call->isGenerator() || !$endEvent = $call->endEvent()) { continue; } list($exception) = $call->generatorResponse(); if ($exception && is_a($exception, $type)) { $matchingEvents[] = $endEvent; ++$matchCount; } } } elseif (is_object($type)) { if ($type instanceof InstanceHandle) { $type = $type->get(); } if ($type instanceof Throwable) { $isTypeSupported = true; $type = $this->matcherFactory->equalTo($type, true); } elseif ($this->matcherFactory->isMatcher($type)) { $isTypeSupported = true; $type = $this->matcherFactory->adapt($type); } if ($isTypeSupported) { foreach ($this->calls as $call) { if ( !$call->isGenerator() || !$endEvent = $call->endEvent() ) { continue; } list($exception) = $call->generatorResponse(); if ($exception && $type->matches($exception)) { $matchingEvents[] = $endEvent; ++$matchCount; } } } } if (!$isTypeSupported) { throw new InvalidArgumentException( sprintf( 'Unable to match exceptions against %s.', $this->assertionRenderer->renderValue($type) ) ); } if ($cardinality->matches($matchCount, $this->callCount)) { return $this->assertionRecorder->createSuccess($matchingEvents); } return null; }
[ "public", "function", "checkThrew", "(", "$", "type", "=", "null", ")", ":", "?", "EventCollection", "{", "$", "cardinality", "=", "$", "this", "->", "resetCardinality", "(", ")", ";", "if", "(", "$", "this", "->", "subject", "instanceof", "Call", ")", ...
Checks if an exception of the supplied type was thrown from a generator. @param Matcher|Throwable|string|null $type An exception to match, the type of exception, or null for any exception. @return EventCollection|null The result. @throws InvalidArgumentException If the type is invalid.
[ "Checks", "if", "an", "exception", "of", "the", "supplied", "type", "was", "thrown", "from", "a", "generator", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L410-L498
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.like
public function like(...$types): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $final = []; foreach ($types as $type) { if (is_array($type)) { if (!empty($type)) { if (array_values($type) === $type) { $final = array_merge($final, $type); } else { $final[] = $type; } } } else { $final[] = $type; } } $toAdd = []; if (!$this->parentClassName) { $parentClassNames = []; } else { $parentClassNames = [$this->parentClassName]; } $parentClassName = ''; $definitions = []; foreach ($final as $type) { if (is_string($type)) { try { $type = new ReflectionClass($type); } catch (ReflectionException $e) { throw new InvalidTypeException($type, $e); } } elseif (is_array($type)) { foreach ($type as $name => $value) { if (!is_string($name)) { throw new InvalidDefinitionException($name, $value); } } $definitions[] = $type; continue; } else { throw new InvalidTypeException($type); } if ($type->isAnonymous()) { throw new AnonymousClassException(); } $isTrait = $type->isTrait(); if (!$isTrait && $type->isFinal()) { throw new FinalClassException($type->getName()); } if (!$isTrait && !$type->isInterface()) { $parentClassNames[] = $parentClassName = $type->getName(); } $toAdd[] = $type; } $parentClassNames = array_unique($parentClassNames); $parentClassCount = count($parentClassNames); if ($parentClassCount > 1) { throw new MultipleInheritanceException($parentClassNames); } foreach ($toAdd as $type) { $name = strtolower($type->getName()); if (!isset($this->types[$name])) { $this->types[$name] = $type; } } if ($parentClassCount > 0) { $this->parentClassName = $parentClassName; } foreach ($definitions as $definition) { $this->define($definition); } return $this; }
php
public function like(...$types): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $final = []; foreach ($types as $type) { if (is_array($type)) { if (!empty($type)) { if (array_values($type) === $type) { $final = array_merge($final, $type); } else { $final[] = $type; } } } else { $final[] = $type; } } $toAdd = []; if (!$this->parentClassName) { $parentClassNames = []; } else { $parentClassNames = [$this->parentClassName]; } $parentClassName = ''; $definitions = []; foreach ($final as $type) { if (is_string($type)) { try { $type = new ReflectionClass($type); } catch (ReflectionException $e) { throw new InvalidTypeException($type, $e); } } elseif (is_array($type)) { foreach ($type as $name => $value) { if (!is_string($name)) { throw new InvalidDefinitionException($name, $value); } } $definitions[] = $type; continue; } else { throw new InvalidTypeException($type); } if ($type->isAnonymous()) { throw new AnonymousClassException(); } $isTrait = $type->isTrait(); if (!$isTrait && $type->isFinal()) { throw new FinalClassException($type->getName()); } if (!$isTrait && !$type->isInterface()) { $parentClassNames[] = $parentClassName = $type->getName(); } $toAdd[] = $type; } $parentClassNames = array_unique($parentClassNames); $parentClassCount = count($parentClassNames); if ($parentClassCount > 1) { throw new MultipleInheritanceException($parentClassNames); } foreach ($toAdd as $type) { $name = strtolower($type->getName()); if (!isset($this->types[$name])) { $this->types[$name] = $type; } } if ($parentClassCount > 0) { $this->parentClassName = $parentClassName; } foreach ($definitions as $definition) { $this->define($definition); } return $this; }
[ "public", "function", "like", "(", "...", "$", "types", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}", "$", "final", "=", "[", "]", ";", "foreach", "(", "$...
Add classes, interfaces, or traits. Each value in `$types` can be either a class name, or an ad hoc mock definition. If only a single type is being mocked, the class name or definition can be passed without being wrapped in an array. @param mixed ...$types Types to add. @return $this This builder. @throws MockException If invalid input is supplied, or this builder is already finalized.
[ "Add", "classes", "interfaces", "or", "traits", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L137-L232
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.addMethod
public function addMethod(string $name, callable $callback = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } if (!$callback) { $callback = $this->emptyCallback; } $this->customMethods[$name] = [ $callback, $this->invocableInspector->callbackReflector($callback), ]; return $this; }
php
public function addMethod(string $name, callable $callback = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } if (!$callback) { $callback = $this->emptyCallback; } $this->customMethods[$name] = [ $callback, $this->invocableInspector->callbackReflector($callback), ]; return $this; }
[ "public", "function", "addMethod", "(", "string", "$", "name", ",", "callable", "$", "callback", "=", "null", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}", "i...
Add a custom method. @param string $name The name. @param callable|null $callback The callback. @return $this This builder. @throws MockException If this builder is already finalized.
[ "Add", "a", "custom", "method", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L243-L258
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.addProperty
public function addProperty(string $name, $value = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $this->customProperties[$name] = $value; return $this; }
php
public function addProperty(string $name, $value = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $this->customProperties[$name] = $value; return $this; }
[ "public", "function", "addProperty", "(", "string", "$", "name", ",", "$", "value", "=", "null", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}", "$", "this", ...
Add a custom property. @param string $name The name. @param mixed $value The value. @return $this This builder. @throws MockException If this builder is already finalized.
[ "Add", "a", "custom", "property", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L269-L278
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.addStaticMethod
public function addStaticMethod( string $name, callable $callback = null ): self { if ($this->isFinalized) { throw new FinalizedMockException(); } if (!$callback) { $callback = $this->emptyCallback; } $this->customStaticMethods[$name] = [ $callback, $this->invocableInspector->callbackReflector($callback), ]; return $this; }
php
public function addStaticMethod( string $name, callable $callback = null ): self { if ($this->isFinalized) { throw new FinalizedMockException(); } if (!$callback) { $callback = $this->emptyCallback; } $this->customStaticMethods[$name] = [ $callback, $this->invocableInspector->callbackReflector($callback), ]; return $this; }
[ "public", "function", "addStaticMethod", "(", "string", "$", "name", ",", "callable", "$", "callback", "=", "null", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}"...
Add a custom static method. @param string $name The name. @param callable|null $callback The callback. @return $this This builder. @throws MockException If this builder is already finalized.
[ "Add", "a", "custom", "static", "method", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L289-L306
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.addStaticProperty
public function addStaticProperty(string $name, $value = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $this->customStaticProperties[$name] = $value; return $this; }
php
public function addStaticProperty(string $name, $value = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $this->customStaticProperties[$name] = $value; return $this; }
[ "public", "function", "addStaticProperty", "(", "string", "$", "name", ",", "$", "value", "=", "null", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}", "$", "thi...
Add a custom static property. @param string $name The name. @param mixed $value The value. @return $this This builder. @throws MockException If this builder is already finalized.
[ "Add", "a", "custom", "static", "property", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L317-L326
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.addConstant
public function addConstant(string $name, $value = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $this->customConstants[$name] = $value; return $this; }
php
public function addConstant(string $name, $value = null): self { if ($this->isFinalized) { throw new FinalizedMockException(); } $this->customConstants[$name] = $value; return $this; }
[ "public", "function", "addConstant", "(", "string", "$", "name", ",", "$", "value", "=", "null", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}", "$", "this", ...
Add a custom class constant. @param string $name The name. @param mixed $value The value. @return $this This builder. @throws MockException If this builder is already finalized.
[ "Add", "a", "custom", "class", "constant", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L337-L346
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.named
public function named(string $className): self { if ($this->isFinalized) { throw new FinalizedMockException(); } if ('' !== $className) { if ( !preg_match('/^' . static::SYMBOL_PATTERN . '$/S', $className) ) { throw new InvalidClassNameException($className); } } $this->className = $className; return $this; }
php
public function named(string $className): self { if ($this->isFinalized) { throw new FinalizedMockException(); } if ('' !== $className) { if ( !preg_match('/^' . static::SYMBOL_PATTERN . '$/S', $className) ) { throw new InvalidClassNameException($className); } } $this->className = $className; return $this; }
[ "public", "function", "named", "(", "string", "$", "className", ")", ":", "self", "{", "if", "(", "$", "this", "->", "isFinalized", ")", "{", "throw", "new", "FinalizedMockException", "(", ")", ";", "}", "if", "(", "''", "!==", "$", "className", ")", ...
Set the class name. @param string $className The class name, or empty string to use a generated name. @return $this This builder. @throws MockException If this builder is already finalized.
[ "Set", "the", "class", "name", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L356-L373
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.finalize
public function finalize(): self { if (!$this->isFinalized) { $this->normalizeDefinition(); $this->isFinalized = true; $this->definition = new MockDefinition( $this->types, $this->customMethods, $this->customProperties, $this->customStaticMethods, $this->customStaticProperties, $this->customConstants, $this->className ); } return $this; }
php
public function finalize(): self { if (!$this->isFinalized) { $this->normalizeDefinition(); $this->isFinalized = true; $this->definition = new MockDefinition( $this->types, $this->customMethods, $this->customProperties, $this->customStaticMethods, $this->customStaticProperties, $this->customConstants, $this->className ); } return $this; }
[ "public", "function", "finalize", "(", ")", ":", "self", "{", "if", "(", "!", "$", "this", "->", "isFinalized", ")", "{", "$", "this", "->", "normalizeDefinition", "(", ")", ";", "$", "this", "->", "isFinalized", "=", "true", ";", "$", "this", "->", ...
Finalize the mock builder. @return $this This builder.
[ "Finalize", "the", "mock", "builder", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L390-L407
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.build
public function build(bool $createNew = false): ReflectionClass { if (!$this->class) { $this->class = $this->factory ->createMockClass($this->definition(), $createNew); } return $this->class; }
php
public function build(bool $createNew = false): ReflectionClass { if (!$this->class) { $this->class = $this->factory ->createMockClass($this->definition(), $createNew); } return $this->class; }
[ "public", "function", "build", "(", "bool", "$", "createNew", "=", "false", ")", ":", "ReflectionClass", "{", "if", "(", "!", "$", "this", "->", "class", ")", "{", "$", "this", "->", "class", "=", "$", "this", "->", "factory", "->", "createMockClass", ...
Generate and define the mock class. Calling this method will finalize the mock builder. @param bool $createNew True if a new class should be created even when a compatible one exists. @return ReflectionClass The class. @throws MockException If the mock generation fails.
[ "Generate", "and", "define", "the", "mock", "class", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L443-L451
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.get
public function get(): Mock { if ($this->mock) { return $this->mock; } $this->mock = $this->factory->createFullMock($this->build()); return $this->mock; }
php
public function get(): Mock { if ($this->mock) { return $this->mock; } $this->mock = $this->factory->createFullMock($this->build()); return $this->mock; }
[ "public", "function", "get", "(", ")", ":", "Mock", "{", "if", "(", "$", "this", "->", "mock", ")", "{", "return", "$", "this", "->", "mock", ";", "}", "$", "this", "->", "mock", "=", "$", "this", "->", "factory", "->", "createFullMock", "(", "$"...
Get a mock. This method will return the current mock, only creating a new mock if no existing mock is available. If no existing mock is available, the created mock will be a full mock. Calling this method will finalize the mock builder. @return Mock The mock instance. @throws MockException If the mock generation fails.
[ "Get", "a", "mock", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L481-L490
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.full
public function full(): Mock { $this->mock = $this->factory->createFullMock($this->build()); return $this->mock; }
php
public function full(): Mock { $this->mock = $this->factory->createFullMock($this->build()); return $this->mock; }
[ "public", "function", "full", "(", ")", ":", "Mock", "{", "$", "this", "->", "mock", "=", "$", "this", "->", "factory", "->", "createFullMock", "(", "$", "this", "->", "build", "(", ")", ")", ";", "return", "$", "this", "->", "mock", ";", "}" ]
Create a new full mock. This method will always create a new mock, and will replace the current mock. Calling this method will finalize the mock builder. @return Mock The mock instance. @throws MockException If the mock generation fails.
[ "Create", "a", "new", "full", "mock", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L503-L508
train
eloquent/phony
src/Mock/Builder/MockBuilder.php
MockBuilder.source
public function source(MockGenerator $generator = null): string { if (!$generator) { $generator = MockGenerator::instance(); } return $generator->generate($this->definition()); }
php
public function source(MockGenerator $generator = null): string { if (!$generator) { $generator = MockGenerator::instance(); } return $generator->generate($this->definition()); }
[ "public", "function", "source", "(", "MockGenerator", "$", "generator", "=", "null", ")", ":", "string", "{", "if", "(", "!", "$", "generator", ")", "{", "$", "generator", "=", "MockGenerator", "::", "instance", "(", ")", ";", "}", "return", "$", "gene...
Get the generated source code of the mock class. Calling this method will finalize the mock builder. @param MockGenerator|null $generator The mock generator to use. @return string The source code. @throws MockException If the mock generation fails.
[ "Get", "the", "generated", "source", "code", "of", "the", "mock", "class", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L564-L571
train
eloquent/phony
src/Verification/GeneratorVerifierFactory.php
GeneratorVerifierFactory.create
public function create($subject, array $calls): GeneratorVerifier { return new GeneratorVerifier( $subject, $calls, $this->matcherFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
php
public function create($subject, array $calls): GeneratorVerifier { return new GeneratorVerifier( $subject, $calls, $this->matcherFactory, $this->callVerifierFactory, $this->assertionRecorder, $this->assertionRenderer ); }
[ "public", "function", "create", "(", "$", "subject", ",", "array", "$", "calls", ")", ":", "GeneratorVerifier", "{", "return", "new", "GeneratorVerifier", "(", "$", "subject", ",", "$", "calls", ",", "$", "this", "->", "matcherFactory", ",", "$", "this", ...
Create a new generator verifier. @param Spy|Call $subject The subject. @param array<Call> $calls The calls. @return GeneratorVerifier The newly created generator verifier.
[ "Create", "a", "new", "generator", "verifier", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifierFactory.php#L74-L84
train
eloquent/phony
src/Matcher/MatcherFactory.php
MatcherFactory.addMatcherDriver
public function addMatcherDriver(MatcherDriver $driver): void { if (!in_array($driver, $this->drivers, true)) { $this->drivers[] = $driver; if ($driver->isAvailable()) { foreach ($driver->matcherClassNames() as $className) { $this->driverIndex[$className] = $driver; } } } }
php
public function addMatcherDriver(MatcherDriver $driver): void { if (!in_array($driver, $this->drivers, true)) { $this->drivers[] = $driver; if ($driver->isAvailable()) { foreach ($driver->matcherClassNames() as $className) { $this->driverIndex[$className] = $driver; } } } }
[ "public", "function", "addMatcherDriver", "(", "MatcherDriver", "$", "driver", ")", ":", "void", "{", "if", "(", "!", "in_array", "(", "$", "driver", ",", "$", "this", "->", "drivers", ",", "true", ")", ")", "{", "$", "this", "->", "drivers", "[", "]...
Add a matcher driver. @param MatcherDriver $driver The matcher driver.
[ "Add", "a", "matcher", "driver", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L60-L71
train
eloquent/phony
src/Matcher/MatcherFactory.php
MatcherFactory.isMatcher
public function isMatcher($value): bool { if (is_object($value)) { if ($value instanceof Matcher) { return true; } foreach ($this->driverIndex as $className => $driver) { if (is_a($value, $className)) { return true; } } } return false; }
php
public function isMatcher($value): bool { if (is_object($value)) { if ($value instanceof Matcher) { return true; } foreach ($this->driverIndex as $className => $driver) { if (is_a($value, $className)) { return true; } } } return false; }
[ "public", "function", "isMatcher", "(", "$", "value", ")", ":", "bool", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "if", "(", "$", "value", "instanceof", "Matcher", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "thi...
Returns true if the supplied value is a matcher. @param mixed $value The value to test. @return bool True if the value is a matcher.
[ "Returns", "true", "if", "the", "supplied", "value", "is", "a", "matcher", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L90-L105
train
eloquent/phony
src/Matcher/MatcherFactory.php
MatcherFactory.adapt
public function adapt($value): Matchable { if ($value instanceof Matchable) { return $value; } if (is_object($value)) { foreach ($this->driverIndex as $className => $driver) { if (is_a($value, $className)) { return $driver->wrapMatcher($value); } } } if ('*' === $value) { return $this->wildcardAnyMatcher; } if ('~' === $value) { return $this->anyMatcher; } return new EqualToMatcher($value, true, $this->exporter); }
php
public function adapt($value): Matchable { if ($value instanceof Matchable) { return $value; } if (is_object($value)) { foreach ($this->driverIndex as $className => $driver) { if (is_a($value, $className)) { return $driver->wrapMatcher($value); } } } if ('*' === $value) { return $this->wildcardAnyMatcher; } if ('~' === $value) { return $this->anyMatcher; } return new EqualToMatcher($value, true, $this->exporter); }
[ "public", "function", "adapt", "(", "$", "value", ")", ":", "Matchable", "{", "if", "(", "$", "value", "instanceof", "Matchable", ")", "{", "return", "$", "value", ";", "}", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "foreach", "(", ...
Create a new matcher for the supplied value. @param mixed $value The value to create a matcher for. @return Matchable The newly created matcher.
[ "Create", "a", "new", "matcher", "for", "the", "supplied", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L114-L137
train
eloquent/phony
src/Matcher/MatcherFactory.php
MatcherFactory.adaptAll
public function adaptAll(array $values): array { $matchers = []; foreach ($values as $value) { if ( $value instanceof Matcher || $value instanceof WildcardMatcher ) { $matchers[] = $value; continue; } if (is_object($value)) { foreach ($this->driverIndex as $className => $driver) { if (is_a($value, $className)) { $matchers[] = $driver->wrapMatcher($value); continue 2; } } } if ('*' === $value) { $matchers[] = $this->wildcardAnyMatcher; } elseif ('~' === $value) { $matchers[] = $this->anyMatcher; } else { $matchers[] = new EqualToMatcher($value, true, $this->exporter); } } return $matchers; }
php
public function adaptAll(array $values): array { $matchers = []; foreach ($values as $value) { if ( $value instanceof Matcher || $value instanceof WildcardMatcher ) { $matchers[] = $value; continue; } if (is_object($value)) { foreach ($this->driverIndex as $className => $driver) { if (is_a($value, $className)) { $matchers[] = $driver->wrapMatcher($value); continue 2; } } } if ('*' === $value) { $matchers[] = $this->wildcardAnyMatcher; } elseif ('~' === $value) { $matchers[] = $this->anyMatcher; } else { $matchers[] = new EqualToMatcher($value, true, $this->exporter); } } return $matchers; }
[ "public", "function", "adaptAll", "(", "array", "$", "values", ")", ":", "array", "{", "$", "matchers", "=", "[", "]", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Matcher", "||", "$", "v...
Create new matchers for the all supplied values. @param array $values The values to create matchers for. @return array<Matchable> The newly created matchers.
[ "Create", "new", "matchers", "for", "the", "all", "supplied", "values", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L146-L180
train
eloquent/phony
src/Spy/IterableSpyFactory.php
IterableSpyFactory.create
public function create(Call $call, $iterable): IterableSpy { if ($iterable instanceof Traversable) { return new TraversableSpy( $call, $iterable, $this->callEventFactory ); } if (is_array($iterable)) { return new ArraySpy($call, $iterable, $this->callEventFactory); } if (is_object($iterable)) { $type = var_export(get_class($iterable), true); } else { $type = gettype($iterable); } throw new InvalidArgumentException( sprintf('Unsupported iterable of type %s.', $type) ); }
php
public function create(Call $call, $iterable): IterableSpy { if ($iterable instanceof Traversable) { return new TraversableSpy( $call, $iterable, $this->callEventFactory ); } if (is_array($iterable)) { return new ArraySpy($call, $iterable, $this->callEventFactory); } if (is_object($iterable)) { $type = var_export(get_class($iterable), true); } else { $type = gettype($iterable); } throw new InvalidArgumentException( sprintf('Unsupported iterable of type %s.', $type) ); }
[ "public", "function", "create", "(", "Call", "$", "call", ",", "$", "iterable", ")", ":", "IterableSpy", "{", "if", "(", "$", "iterable", "instanceof", "Traversable", ")", "{", "return", "new", "TraversableSpy", "(", "$", "call", ",", "$", "iterable", ",...
Create a new iterable spy. @param Call $call The call from which the iterable originated. @param iterable $iterable The iterable. @return IterableSpy The newly created iterable spy. @throws InvalidArgumentException If the supplied iterable is invalid.
[ "Create", "a", "new", "iterable", "spy", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/IterableSpyFactory.php#L50-L73
train
eloquent/phony
src/Reflection/FeatureDetector.php
FeatureDetector.isSupported
public function isSupported(string $feature): bool { if (!array_key_exists($feature, $this->supported)) { if (!isset($this->features[$feature])) { throw new UndefinedFeatureException($feature); } $this->supported[$feature] = (bool) $this->features[$feature]($this); } return $this->supported[$feature]; }
php
public function isSupported(string $feature): bool { if (!array_key_exists($feature, $this->supported)) { if (!isset($this->features[$feature])) { throw new UndefinedFeatureException($feature); } $this->supported[$feature] = (bool) $this->features[$feature]($this); } return $this->supported[$feature]; }
[ "public", "function", "isSupported", "(", "string", "$", "feature", ")", ":", "bool", "{", "if", "(", "!", "array_key_exists", "(", "$", "feature", ",", "$", "this", "->", "supported", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", ...
Returns true if the specified feature is supported by the current runtime environment. @param string $feature The feature. @return bool True if supported. @throws UndefinedFeatureException If the specified feature is undefined.
[ "Returns", "true", "if", "the", "specified", "feature", "is", "supported", "by", "the", "current", "runtime", "environment", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Reflection/FeatureDetector.php#L91-L103
train
eloquent/phony
src/Reflection/FeatureDetector.php
FeatureDetector.standardFeatures
public function standardFeatures(): array { return [ 'stdout.ansi' => function () { // @codeCoverageIgnoreStart if (DIRECTORY_SEPARATOR === '\\') { return 0 >= version_compare( '10.0.10586', PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD ) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM') || false !== getenv('BABUN_HOME'); } // @codeCoverageIgnoreEnd return function_exists('posix_isatty') && @posix_isatty(STDOUT); }, 'type.object' => function () { try { $function = new ReflectionFunction(function (object $a) {}); $parameters = $function->getParameters(); $result = null === $parameters[0]->getClass(); // @codeCoverageIgnoreStart } catch (ReflectionException $e) { $result = false; } // @codeCoverageIgnoreEnd return $result; }, ]; }
php
public function standardFeatures(): array { return [ 'stdout.ansi' => function () { // @codeCoverageIgnoreStart if (DIRECTORY_SEPARATOR === '\\') { return 0 >= version_compare( '10.0.10586', PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD ) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM') || false !== getenv('BABUN_HOME'); } // @codeCoverageIgnoreEnd return function_exists('posix_isatty') && @posix_isatty(STDOUT); }, 'type.object' => function () { try { $function = new ReflectionFunction(function (object $a) {}); $parameters = $function->getParameters(); $result = null === $parameters[0]->getClass(); // @codeCoverageIgnoreStart } catch (ReflectionException $e) { $result = false; } // @codeCoverageIgnoreEnd return $result; }, ]; }
[ "public", "function", "standardFeatures", "(", ")", ":", "array", "{", "return", "[", "'stdout.ansi'", "=>", "function", "(", ")", "{", "// @codeCoverageIgnoreStart", "if", "(", "DIRECTORY_SEPARATOR", "===", "'\\\\'", ")", "{", "return", "0", ">=", "version_comp...
Get the standard feature detection callbacks. @return array<string,callable> The standard features.
[ "Get", "the", "standard", "feature", "detection", "callbacks", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Reflection/FeatureDetector.php#L110-L148
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.calls
public function calls(callable ...$callbacks): self { foreach ($callbacks as $callback) { $this->callsWith($callback); } return $this; }
php
public function calls(callable ...$callbacks): self { foreach ($callbacks as $callback) { $this->callsWith($callback); } return $this; }
[ "public", "function", "calls", "(", "callable", "...", "$", "callbacks", ")", ":", "self", "{", "foreach", "(", "$", "callbacks", "as", "$", "callback", ")", "{", "$", "this", "->", "callsWith", "(", "$", "callback", ")", ";", "}", "return", "$", "th...
Add a callback to be called as part of the answer. @param callable ...$callbacks The callbacks. @return $this This builder.
[ "Add", "a", "callback", "to", "be", "called", "as", "part", "of", "the", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L49-L56
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.setsArgument
public function setsArgument($indexOrValue = null, $value = null): self { if (func_num_args() > 1) { $index = $indexOrValue; } else { $index = 0; $value = $indexOrValue; } if ($value instanceof InstanceHandle) { $value = $value->get(); } return $this->callsWith( function ($arguments) use ($index, $value) { $arguments->set($index, $value); }, [], false, true, false ); }
php
public function setsArgument($indexOrValue = null, $value = null): self { if (func_num_args() > 1) { $index = $indexOrValue; } else { $index = 0; $value = $indexOrValue; } if ($value instanceof InstanceHandle) { $value = $value->get(); } return $this->callsWith( function ($arguments) use ($index, $value) { $arguments->set($index, $value); }, [], false, true, false ); }
[ "public", "function", "setsArgument", "(", "$", "indexOrValue", "=", "null", ",", "$", "value", "=", "null", ")", ":", "self", "{", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "{", "$", "index", "=", "$", "indexOrValue", ";", "}", "else", ...
Set the value of an argument passed by reference as part of the answer. If called with no arguments, sets the first argument to null. If called with one argument, sets the first argument to $indexOrValue. If called with two arguments, sets the argument at $indexOrValue to $value. @param mixed $indexOrValue The index, or value if no index is specified. @param mixed $value The value. @return $this This builder.
[ "Set", "the", "value", "of", "an", "argument", "passed", "by", "reference", "as", "part", "of", "the", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L198-L220
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.yields
public function yields($keyOrValue = null, $value = null): self { $argumentCount = func_num_args(); if ($argumentCount > 1) { $hasKey = true; $hasValue = true; $key = $keyOrValue; } elseif ($argumentCount > 0) { $hasKey = false; $hasValue = true; $key = null; $value = $keyOrValue; } else { $hasKey = false; $hasValue = false; $key = null; } if ($key instanceof InstanceHandle) { $key = $key->get(); } if ($value instanceof InstanceHandle) { $value = $value->get(); } $this->iterations[] = new GeneratorYieldIteration( $this->requests, $hasKey, $key, $hasValue, $value ); $this->requests = []; return $this; }
php
public function yields($keyOrValue = null, $value = null): self { $argumentCount = func_num_args(); if ($argumentCount > 1) { $hasKey = true; $hasValue = true; $key = $keyOrValue; } elseif ($argumentCount > 0) { $hasKey = false; $hasValue = true; $key = null; $value = $keyOrValue; } else { $hasKey = false; $hasValue = false; $key = null; } if ($key instanceof InstanceHandle) { $key = $key->get(); } if ($value instanceof InstanceHandle) { $value = $value->get(); } $this->iterations[] = new GeneratorYieldIteration( $this->requests, $hasKey, $key, $hasValue, $value ); $this->requests = []; return $this; }
[ "public", "function", "yields", "(", "$", "keyOrValue", "=", "null", ",", "$", "value", "=", "null", ")", ":", "self", "{", "$", "argumentCount", "=", "func_num_args", "(", ")", ";", "if", "(", "$", "argumentCount", ">", "1", ")", "{", "$", "hasKey",...
Add a yielded value to the answer. If both `$keyOrValue` and `$value` are supplied, the stub will yield like `yield $keyOrValue => $value;`. If only `$keyOrValue` is supplied, the stub will yield like `yield $keyOrValue;`. If no arguments are supplied, the stub will yield like `yield;`. @param mixed $keyOrValue The key or value. @param mixed $value The value. @return $this This builder.
[ "Add", "a", "yielded", "value", "to", "the", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L238-L275
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.yieldsFrom
public function yieldsFrom($values): self { $this->iterations[] = new GeneratorYieldFromIteration($this->requests, $values); $this->requests = []; return $this; }
php
public function yieldsFrom($values): self { $this->iterations[] = new GeneratorYieldFromIteration($this->requests, $values); $this->requests = []; return $this; }
[ "public", "function", "yieldsFrom", "(", "$", "values", ")", ":", "self", "{", "$", "this", "->", "iterations", "[", "]", "=", "new", "GeneratorYieldFromIteration", "(", "$", "this", "->", "requests", ",", "$", "values", ")", ";", "$", "this", "->", "r...
Add a set of yielded values to the answer. @param mixed<mixed,mixed> $values The set of keys and values to yield. @return $this This builder.
[ "Add", "a", "set", "of", "yielded", "values", "to", "the", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L284-L291
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.returns
public function returns(...$values): Stub { if (empty($values)) { $values = [null]; } $value = $values[0]; $argumentCount = count($values); $copies = []; for ($i = 1; $i < $argumentCount; ++$i) { $copies[$i] = clone $this; } if ($value instanceof InstanceHandle) { $value = $value->get(); } $this->returnValue = $value; $this->returnsArgument = null; $this->returnsSelf = false; for ($i = 1; $i < $argumentCount; ++$i) { $this->stub ->doesWith($copies[$i]->answer(), [], true, true, false); $copies[$i]->returns($values[$i]); } return $this->stub; }
php
public function returns(...$values): Stub { if (empty($values)) { $values = [null]; } $value = $values[0]; $argumentCount = count($values); $copies = []; for ($i = 1; $i < $argumentCount; ++$i) { $copies[$i] = clone $this; } if ($value instanceof InstanceHandle) { $value = $value->get(); } $this->returnValue = $value; $this->returnsArgument = null; $this->returnsSelf = false; for ($i = 1; $i < $argumentCount; ++$i) { $this->stub ->doesWith($copies[$i]->answer(), [], true, true, false); $copies[$i]->returns($values[$i]); } return $this->stub; }
[ "public", "function", "returns", "(", "...", "$", "values", ")", ":", "Stub", "{", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "$", "values", "=", "[", "null", "]", ";", "}", "$", "value", "=", "$", "values", "[", "0", "]", ";", "$...
End the generator by returning a value. Calling this method with no arguments is equivalent to calling it with a single argument of `null`. @param mixed ...$values The return values. @return Stub The stub.
[ "End", "the", "generator", "by", "returning", "a", "value", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L303-L333
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.throws
public function throws(...$exceptions): Stub { if (empty($exceptions)) { $exceptions = [new Exception()]; } $exception = $exceptions[0]; $argumentCount = count($exceptions); $copies = []; for ($i = 1; $i < $argumentCount; ++$i) { $copies[$i] = clone $this; } if (is_string($exception)) { $exception = new Exception($exception); } elseif ($exception instanceof InstanceHandle) { $exception = $exception->get(); } $this->exception = $exception; for ($i = 1; $i < $argumentCount; ++$i) { $this->stub ->doesWith($copies[$i]->answer(), [], true, true, false); $copies[$i]->throws($exceptions[$i]); } return $this->stub; }
php
public function throws(...$exceptions): Stub { if (empty($exceptions)) { $exceptions = [new Exception()]; } $exception = $exceptions[0]; $argumentCount = count($exceptions); $copies = []; for ($i = 1; $i < $argumentCount; ++$i) { $copies[$i] = clone $this; } if (is_string($exception)) { $exception = new Exception($exception); } elseif ($exception instanceof InstanceHandle) { $exception = $exception->get(); } $this->exception = $exception; for ($i = 1; $i < $argumentCount; ++$i) { $this->stub ->doesWith($copies[$i]->answer(), [], true, true, false); $copies[$i]->throws($exceptions[$i]); } return $this->stub; }
[ "public", "function", "throws", "(", "...", "$", "exceptions", ")", ":", "Stub", "{", "if", "(", "empty", "(", "$", "exceptions", ")", ")", "{", "$", "exceptions", "=", "[", "new", "Exception", "(", ")", "]", ";", "}", "$", "exception", "=", "$", ...
End the generator by throwing an exception. Calling this method with no arguments is equivalent to calling it with a single argument of `null`. @param Throwable|string|null ...$exceptions The exceptions, or messages, or nulls to throw generic exceptions. @return Stub The stub.
[ "End", "the", "generator", "by", "throwing", "an", "exception", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L374-L404
train
eloquent/phony
src/Stub/Answer/Builder/GeneratorAnswerBuilder.php
GeneratorAnswerBuilder.answer
public function answer(): callable { return function ($self, $arguments) { foreach ($this->iterations as $iteration) { foreach ($iteration->requests as $request) { $this->invoker->callWith( $request->callback(), $request->finalArguments($self, $arguments) ); } if ($iteration instanceof GeneratorYieldFromIteration) { foreach ($iteration->values as $key => $value) { if ($key instanceof InstanceHandle) { $key = $key->get(); } if ($value instanceof InstanceHandle) { $value = $value->get(); } yield $key => $value; } } else { if ($iteration->hasKey) { yield $iteration->key => $iteration->value; } elseif ($iteration->hasValue) { yield $iteration->value; } else { yield; } } } foreach ($this->requests as $request) { $this->invoker->callWith( $request->callback(), $request->finalArguments($self, $arguments) ); } if ($this->exception) { throw $this->exception; } if ($this->returnsSelf) { return $self; } if (null !== $this->returnsArgument) { return $arguments->get($this->returnsArgument); } return $this->returnValue; }; }
php
public function answer(): callable { return function ($self, $arguments) { foreach ($this->iterations as $iteration) { foreach ($iteration->requests as $request) { $this->invoker->callWith( $request->callback(), $request->finalArguments($self, $arguments) ); } if ($iteration instanceof GeneratorYieldFromIteration) { foreach ($iteration->values as $key => $value) { if ($key instanceof InstanceHandle) { $key = $key->get(); } if ($value instanceof InstanceHandle) { $value = $value->get(); } yield $key => $value; } } else { if ($iteration->hasKey) { yield $iteration->key => $iteration->value; } elseif ($iteration->hasValue) { yield $iteration->value; } else { yield; } } } foreach ($this->requests as $request) { $this->invoker->callWith( $request->callback(), $request->finalArguments($self, $arguments) ); } if ($this->exception) { throw $this->exception; } if ($this->returnsSelf) { return $self; } if (null !== $this->returnsArgument) { return $arguments->get($this->returnsArgument); } return $this->returnValue; }; }
[ "public", "function", "answer", "(", ")", ":", "callable", "{", "return", "function", "(", "$", "self", ",", "$", "arguments", ")", "{", "foreach", "(", "$", "this", "->", "iterations", "as", "$", "iteration", ")", "{", "foreach", "(", "$", "iteration"...
Get the answer. @return callable The answer.
[ "Get", "the", "answer", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L411-L466
train
eloquent/phony
src/Call/CallFactory.php
CallFactory.record
public function record( $callback, Arguments $arguments, SpyData $spy ): CallData { $originalArguments = $arguments->copy(); $call = new CallData( $spy->nextIndex(), $this->eventFactory->createCalled($spy, $originalArguments) ); $spy->addCall($call); $returnValue = null; $exception = null; try { $returnValue = $this->invoker->callWith($callback, $arguments); } catch (Throwable $exception) { // handled below } if ($exception) { $responseEvent = $this->eventFactory->createThrew($exception); } else { $responseEvent = $this->eventFactory->createReturned($returnValue); } $call->setResponseEvent($responseEvent); return $call; }
php
public function record( $callback, Arguments $arguments, SpyData $spy ): CallData { $originalArguments = $arguments->copy(); $call = new CallData( $spy->nextIndex(), $this->eventFactory->createCalled($spy, $originalArguments) ); $spy->addCall($call); $returnValue = null; $exception = null; try { $returnValue = $this->invoker->callWith($callback, $arguments); } catch (Throwable $exception) { // handled below } if ($exception) { $responseEvent = $this->eventFactory->createThrew($exception); } else { $responseEvent = $this->eventFactory->createReturned($returnValue); } $call->setResponseEvent($responseEvent); return $call; }
[ "public", "function", "record", "(", "$", "callback", ",", "Arguments", "$", "arguments", ",", "SpyData", "$", "spy", ")", ":", "CallData", "{", "$", "originalArguments", "=", "$", "arguments", "->", "copy", "(", ")", ";", "$", "call", "=", "new", "Cal...
Record call details by invoking a callback. @param callable $callback The callback. @param Arguments $arguments The arguments. @param SpyData $spy The spy to record the call to. @return CallData The newly created call.
[ "Record", "call", "details", "by", "invoking", "a", "callback", "." ]
54ac8a937079da0d818d82aaf5edd61501c48f2c
https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallFactory.php#L57-L88
train