code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function testShouldThrowExceptionIfMatchedIsNotVariable(): void
{
$this->expectException(CompilerException::class);
$this->expectExceptionMessage('Only variables can be passed by reference');
$optimizer = new PregMatchOptimizer();
$expression = [
'parameters' => [
0 => [/* skip */],
1 => [/* skip */],
2 => ['parameter' => ['type' => 'int']],
],
];
$optimizer->optimize(
$expression,
$this->callMock,
$this->contextMock
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1697
|
testShouldThrowExceptionIfMatchedIsNotVariable
|
php
|
zephir-lang/zephir
|
tests/Zephir/Optimizers/FunctionCall/PregMatchOptimizerTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Optimizers/FunctionCall/PregMatchOptimizerTest.php
|
MIT
|
public function testShouldThrowExceptionIfUsedUndefinedMatchesVariable(): void
{
$this->expectException(CompilerException::class);
$this->expectExceptionMessage("Cannot mutate variable 'matches' because it wasn't defined");
$optimizer = new PregMatchOptimizer();
$expression = [
'parameters' => [
0 => [/* skip */],
1 => [/* skip */],
2 => ['parameter' => ['type' => 'variable', 'value' => 'matches']],
],
];
$context = new \ReflectionClass(CompilationContext::class);
$this->symTableMock
->expects($this->once())
->method('getVariable')
->with('matches')
->willReturn(false);
$symbolTable = $context->getProperty('symbolTable');
$symbolTable->setValue($this->contextMock, $this->symTableMock);
$optimizer->optimize(
$expression,
$this->callMock,
$this->contextMock
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1697
|
testShouldThrowExceptionIfUsedUndefinedMatchesVariable
|
php
|
zephir-lang/zephir
|
tests/Zephir/Optimizers/FunctionCall/PregMatchOptimizerTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Optimizers/FunctionCall/PregMatchOptimizerTest.php
|
MIT
|
public function testShouldThrowExceptionIfMatchesHasUnexpectedType(): void
{
$this->expectException(CompilerException::class);
$this->expectExceptionMessage("The 'matches' variable must be either a variable or an array, got Ooops");
$optimizer = new PregMatchOptimizer();
$expression = [
'parameters' => [
0 => [/* skip */],
1 => [/* skip */],
2 => ['parameter' => ['type' => 'variable', 'value' => 'matches']],
],
];
$context = new \ReflectionClass(CompilationContext::class);
$this->variableMock
->expects($this->exactly(2))
->method('getType')
->willReturn('Ooops');
$this->symTableMock
->expects($this->once())
->method('getVariable')
->with('matches')
->willReturn($this->variableMock);
$symbolTable = $context->getProperty('symbolTable');
$symbolTable->setValue($this->contextMock, $this->symTableMock);
$optimizer->optimize(
$expression,
$this->callMock,
$this->contextMock
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1697
|
testShouldThrowExceptionIfMatchesHasUnexpectedType
|
php
|
zephir-lang/zephir
|
tests/Zephir/Optimizers/FunctionCall/PregMatchOptimizerTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Optimizers/FunctionCall/PregMatchOptimizerTest.php
|
MIT
|
public function testThrowsExceptionForWrongVariables(array $statement, string $message, callable $setProperty): void
{
$zephirVariable = new ZephirVariable('variable', 'foo');
// call necessary setters for test case
$setProperty($zephirVariable);
$this->expectException(CompilerException::class);
$this->expectExceptionCode(0);
$this->expectExceptionMessage($message);
$this->test->assign('foo', $zephirVariable, $this->compiledExpr, $this->readDetector, $this->compilationCtx, $statement);
}
|
@dataProvider exceptionTestProvider
@param array $statement
@param string $message - Expected error message
@param callable $setProperty - Callback func to set required for test property
|
testThrowsExceptionForWrongVariables
|
php
|
zephir-lang/zephir
|
tests/Zephir/Statements/Let/VariableTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Statements/Let/VariableTest.php
|
MIT
|
private function getMethod(string $name)
{
$method = $this->generatorClass->getMethod($name);
$method->setAccessible(true);
return $method;
}
|
Modify method visibility to call protected.
@param string $name - method name
@return mixed
@throws \ReflectionException
|
getMethod
|
php
|
zephir-lang/zephir
|
tests/Zephir/Stubs/GeneratorTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Stubs/GeneratorTest.php
|
MIT
|
public function propertyProvider(): array
{
return [
// [ visibility ], type, value, expected
[
['public'], 'int', 1, 'public $testProperty = 1;',
],
[
['protected'], 'bool', 0, 'protected $testProperty = 0;',
],
[
['static'], 'string', 'A', 'static private $testProperty = \'A\';',
],
[
['static', 'error'], 'empty-array', null, 'static private $testProperty = [];',
],
[
[], 'null', null, 'private $testProperty = null;',
],
];
}
|
Provide test case data for buildProperty method test.
|
propertyProvider
|
php
|
zephir-lang/zephir
|
tests/Zephir/Stubs/GeneratorTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Stubs/GeneratorTest.php
|
MIT
|
public function testShouldBuildProperty(array $visibility, string $type, $value, string $expected): void
{
if (Os::isWindows()) {
$this->markTestSkipped('Warning: Strings contain different line endings!');
}
$original = [
'default' => [
'type' => $type,
'value' => $value,
],
];
// Test requirements initialization
$buildClass = $this->getMethod('buildProperty');
$classProperty = new Property(
$this->classDefinition,
$visibility,
'testProperty',
null,
'',
$original
);
// protected function buildProperty(ClassProperty $property, string $indent): string
$actual = $buildClass->invokeArgs(
$this->testClass,
[
$classProperty,
'',
]
);
$this->assertSame($expected, $actual);
}
|
@dataProvider propertyProvider
@covers \Zephir\Stubs\Generator::buildProperty
@param array $visibility
@param string $type
@param $value
@param string $expected
@throws \ReflectionException
|
testShouldBuildProperty
|
php
|
zephir-lang/zephir
|
tests/Zephir/Stubs/GeneratorTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Stubs/GeneratorTest.php
|
MIT
|
public function testShouldBuildConstant(string $type, $value, string $expected): void
{
if (Os::isWindows()) {
$this->markTestSkipped('Warning: Strings contain different line endings!');
}
$buildClass = $this->getMethod('buildConstant');
$extended = [];
if ('static-constant-access' === $type) {
$extended = [
'left' => [
'value' => $value['left'],
],
'right' => [
'value' => $value['right'],
],
];
}
if ('array' === $type) {
$extended = $value;
}
$classConstant = new Constant(
'TEST',
[
'type' => $type,
'value' => $value,
] + $extended,
''
);
// protected function buildConstant(ClassConstant $constant, string $indent): string
$actual = $buildClass->invokeArgs(
$this->testClass,
[
$classConstant,
'',
]
);
$this->assertSame($expected, $actual);
}
|
@dataProvider constantProvider
@param string $type
@param $value
@param string $expected
@throws \ReflectionException
|
testShouldBuildConstant
|
php
|
zephir-lang/zephir
|
tests/Zephir/Stubs/GeneratorTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Stubs/GeneratorTest.php
|
MIT
|
public function testMethodsWithDataSet(array $parameters, string $expected): void
{
$baseDefinition = require ZEPHIRPATH.'/tests/fixtures/base-definition.php';
$baseDefinition['method']['parameters'][] = $parameters;
$this->assertSame($expected, $this->prepareMethod($baseDefinition)->processMethodDocBlock());
}
|
@dataProvider getDocBlock()
@param array $parameters
@param string $expected
|
testMethodsWithDataSet
|
php
|
zephir-lang/zephir
|
tests/Zephir/Stubs/MethodDocBlockTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Stubs/MethodDocBlockTest.php
|
MIT
|
public function testShouldParseDocBlock(string $zephirDocBlock, string $phpDocBlock): void
{
$classMethod = new Method(
new Definition('Zephir', 'testMethod'),
['public'],
'exampleMethodName',
null,
null,
"/**\n * {$zephirDocBlock}\n */"
);
$docblock = new MethodDocBlock($classMethod, new AliasManager(), '');
$expected = "/**\n * {$phpDocBlock}\n */";
$this->assertSame($expected, $docblock->processMethodDocBlock());
}
|
@dataProvider docBlockProvider()
@param string $zephirDocBlock
@param string $phpDocBlock
|
testShouldParseDocBlock
|
php
|
zephir-lang/zephir
|
tests/Zephir/Stubs/MethodDocBlockTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Zephir/Stubs/MethodDocBlockTest.php
|
MIT
|
public function __construct(FormFlowInterface $flow, FormInterface $currentStepForm) {
parent::__construct($flow);
$this->currentStepForm = $currentStepForm;
}
|
@param FormFlowInterface $flow
@param FormInterface $currentStepForm
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Event/FlowExpiredEvent.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Event/FlowExpiredEvent.php
|
MIT
|
public function __construct(FormFlowInterface $flow, $formData) {
parent::__construct($flow);
$this->formData = $formData;
}
|
@param FormFlowInterface $flow
@param mixed $formData
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Event/PostBindFlowEvent.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Event/PostBindFlowEvent.php
|
MIT
|
public function __construct(FormFlowInterface $flow, $formData, $stepNumber) {
parent::__construct($flow);
$this->formData = $formData;
$this->stepNumber = $stepNumber;
}
|
@param FormFlowInterface $flow
@param mixed $formData
@param int $stepNumber
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Event/PostBindRequestEvent.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Event/PostBindRequestEvent.php
|
MIT
|
public function __construct(FormFlowInterface $flow, $formData, $stepNumber) {
parent::__construct($flow);
$this->formData = $formData;
$this->stepNumber = $stepNumber;
}
|
@param FormFlowInterface $flow
@param mixed $formData
@param int $stepNumber
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Event/PostBindSavedDataEvent.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Event/PostBindSavedDataEvent.php
|
MIT
|
public function __construct(FormFlowInterface $flow, $formData) {
parent::__construct($flow);
$this->formData = $formData;
}
|
@param FormFlowInterface $flow
@param mixed $formData
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Event/PostValidateEvent.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Event/PostValidateEvent.php
|
MIT
|
public function __construct(FormFlowInterface $flow, FormInterface $currentStepForm, $invalidStepNumber) {
parent::__construct($flow);
$this->currentStepForm = $currentStepForm;
$this->invalidStepNumber = $invalidStepNumber;
}
|
@param FormFlowInterface $flow
@param FormInterface $currentStepForm
@param int $invalidStepNumber
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Event/PreviousStepInvalidEvent.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Event/PreviousStepInvalidEvent.php
|
MIT
|
public function getRequest() {
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest === null) {
throw new \RuntimeException('The request is not available.');
}
return $currentRequest;
}
|
@return Request
@throws \RuntimeException If the request is not available.
|
getRequest
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
protected function applySkipping($stepNumber, $direction = 1, $boundsReached = 0) {
if ($direction !== 1 && $direction !== -1) {
throw new \InvalidArgumentException(sprintf('Argument of either -1 or 1 expected, "%s" given.', $direction));
}
$stepNumber = $this->ensureStepNumberRange($stepNumber);
if ($this->isStepSkipped($stepNumber)) {
$stepNumber += $direction;
// change direction if outer bounds are reached
if ($direction === 1 && $stepNumber > $this->getStepCount()) {
$direction = -1;
++$boundsReached;
} elseif ($direction === -1 && $stepNumber < 1) {
$direction = 1;
++$boundsReached;
}
if ($boundsReached > 2) {
throw new AllStepsSkippedException();
}
return $this->applySkipping($stepNumber, $direction, $boundsReached);
}
return $stepNumber;
}
|
@param int $stepNumber Assumed step to which skipped steps shall be applied to.
@param int $direction Either 1 (to skip forwards) or -1 (to skip backwards).
@param int $boundsReached Internal counter to avoid endlessly bouncing back and forth.
@return int Target step number with skipping applied.
@throws \InvalidArgumentException If the value of <code>$direction</code> is invalid.
|
applySkipping
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
protected function determineCurrentStepNumber() {
$requestedStepNumber = $this->getRequestedStepNumber();
if ($this->getRequestedTransition() === self::TRANSITION_BACK) {
--$requestedStepNumber;
}
$requestedStepNumber = $this->ensureStepNumberRange($requestedStepNumber);
$requestedStepNumber = $this->refineCurrentStepNumber($requestedStepNumber);
if ($this->getRequestedTransition() === self::TRANSITION_BACK) {
$requestedStepNumber = $this->applySkipping($requestedStepNumber, -1);
// re-evaluate to not keep following steps marked as skipped (after skipping them while going back)
foreach ($this->getSteps() as $step) {
$step->evaluateSkipping($requestedStepNumber, $this);
}
} else {
$requestedStepNumber = $this->applySkipping($requestedStepNumber);
}
return $requestedStepNumber;
}
|
Finds out which step is the current one.
@return int
|
determineCurrentStepNumber
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
private function ensureStepNumberRange($stepNumber) {
return max(min($stepNumber, $this->getStepCount()), 1);
}
|
Ensures that the step number is within the range of defined steps to avoid a possible OutOfBoundsException.
@param int $stepNumber
@return int
|
ensureStepNumberRange
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
protected function refineCurrentStepNumber($refinedStepNumber) {
foreach ($this->getSteps() as $step) {
$step->evaluateSkipping($refinedStepNumber, $this);
}
return $refinedStepNumber;
}
|
Refines the current step number by evaluating and considering skipped steps.
@param int $refinedStepNumber
@return int
|
refineCurrentStepNumber
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
public function invalidateStepData($fromStepNumber) {
$stepData = $this->retrieveStepData();
for ($step = $fromStepNumber, $stepCount = $this->getStepCount(); $step < $stepCount; ++$step) {
unset($stepData[$step]);
}
$this->saveStepData($stepData);
}
|
Invalidates data for steps >= $fromStepNumber.
@param int $fromStepNumber
|
invalidateStepData
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
protected function applyDataFromSavedSteps() {
$stepData = $this->retrieveStepData();
$this->stepForms = [];
$options = [];
if (!$this->revalidatePreviousSteps) {
$options['validation_groups'] = false; // disable validation
}
foreach ($this->getSteps() as $step) {
$stepNumber = $step->getNumber();
if (array_key_exists($stepNumber, $stepData)) {
$stepForm = $this->createFormForStep($stepNumber, $options);
$stepForm->submit($stepData[$stepNumber]); // the form is validated here
if ($this->revalidatePreviousSteps) {
$this->stepForms[$stepNumber] = $stepForm;
}
if ($this->hasListeners(FormFlowEvents::POST_BIND_SAVED_DATA)) {
$this->dispatchEvent(new PostBindSavedDataEvent($this, $this->formData, $stepNumber), FormFlowEvents::POST_BIND_SAVED_DATA);
}
}
}
}
|
Updates form data class with previously saved form data of all steps.
|
applyDataFromSavedSteps
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
protected function createFormForStep($stepNumber, array $options = []) {
$formType = $this->getStep($stepNumber)->getFormType();
$options = $this->getFormOptions($stepNumber, $options);
if ($formType === null) {
$formType = FormType::class;
}
return $this->formFactory->create($formType, $this->formData, $options);
}
|
Creates the form for the given step number.
@param int $stepNumber
@param array $options
@return FormInterface
|
createFormForStep
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
public function createStepsFromConfig(array $stepsConfig) {
$steps = [];
// fix array indexes not starting at 0
$stepsConfig = array_values($stepsConfig);
foreach ($stepsConfig as $index => $stepConfig) {
$steps[] = Step::createFromConfig($index + 1, $stepConfig);
}
return $steps;
}
|
Creates all steps from the given configuration.
@param array $stepsConfig
@return StepInterface[] Value with index 0 is step 1.
|
createStepsFromConfig
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
protected function loadStepsConfig() {
return [];
}
|
Defines the configuration for all steps of this flow.
@return array
|
loadStepsConfig
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
private function dispatchEvent($event, $eventName) {
$this->eventDispatcher->dispatch($event, $eventName);
}
|
@param FormFlowEvent $event
@param string $eventName
|
dispatchEvent
|
php
|
craue/CraueFormFlowBundle
|
Form/FormFlow.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/FormFlow.php
|
MIT
|
public function setFormType($formType) {
if ($formType === null || is_string($formType) || $formType instanceof FormTypeInterface) {
$this->formType = $formType;
return;
}
throw new InvalidTypeException($formType, ['null', 'string', FormTypeInterface::class]);
}
|
@param FormTypeInterface|string|null $formType
@throws InvalidTypeException
|
setFormType
|
php
|
craue/CraueFormFlowBundle
|
Form/Step.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/Step.php
|
MIT
|
public function setSkip($skip) {
if (is_bool($skip)) {
$this->skipFunction = null;
$this->skipped = $skip;
return;
}
if (is_callable($skip)) {
$this->skipFunction = $skip;
$this->skipped = null;
return;
}
throw new InvalidTypeException($skip, ['bool', 'callable']);
}
|
@param bool|callable $skip
@throws InvalidTypeException
|
setSkip
|
php
|
craue/CraueFormFlowBundle
|
Form/Step.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/Step.php
|
MIT
|
private final function __construct($value, $callable = false) {
$this->setValue($value, $callable);
}
|
@param string|callable|null $value
@param bool $callable
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Form/StepLabel.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/StepLabel.php
|
MIT
|
private function setValue($value, $callable = false) {
if ($callable) {
if (!is_callable($value)) {
throw new InvalidTypeException($value, ['callable']);
}
} else {
if ($value !== null && !is_string($value)) {
throw new InvalidTypeException($value, ['null', 'string']);
}
}
$this->callable = $callable;
$this->value = $value;
}
|
@param string|callable|null $value
@param bool $callable
|
setValue
|
php
|
craue/CraueFormFlowBundle
|
Form/StepLabel.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Form/StepLabel.php
|
MIT
|
private function getRawValueForKey($key) {
$qb = $this->conn->createQueryBuilder()
->select($this->valueColumn)
->from(self::TABLE)
->where($this->keyColumn . ' = :key')
->setParameter('key', $this->generateKey($key))
;
// TODO just call `executeQuery()` as soon as DBAL >= 2.13.1 is required
$result = \method_exists($qb, 'executeQuery') ? $qb->executeQuery() : $qb->execute();
// TODO remove as soon as Doctrine DBAL >= 3.0 is required
if (!\method_exists($result, 'fetchOne')) {
return $result->fetchColumn();
}
return $result->fetchOne();
}
|
Gets stored raw data for the given key.
@param string $key
@return string|false Raw data or false, if no data is available.
|
getRawValueForKey
|
php
|
craue/CraueFormFlowBundle
|
Storage/DoctrineStorage.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Storage/DoctrineStorage.php
|
MIT
|
public function __construct($file) {
if (!self::isSupported($file)) {
throw new InvalidTypeException($file, UploadedFile::class);
}
$this->content = base64_encode(file_get_contents($file->getPathname()));
$this->type = UploadedFile::class;
$this->clientOriginalName = $file->getClientOriginalName();
$this->clientMimeType = $file->getClientMimeType();
}
|
@param mixed $file An object meant to be serialized.
@throws InvalidTypeException If the type of <code>$file</code> is unsupported.
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Storage/SerializableFile.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Storage/SerializableFile.php
|
MIT
|
public function getAsFile($tempDir = null) {
if ($tempDir === null) {
$tempDir = sys_get_temp_dir();
}
// create a temporary file with its original content
$tempFile = tempnam($tempDir, 'craue_form_flow_serialized_file');
file_put_contents($tempFile, base64_decode($this->content, true));
TempFileUtil::addTempFile($tempFile);
return new UploadedFile($tempFile, $this->clientOriginalName, $this->clientMimeType, null, true);
}
|
@param string|null $tempDir Directory for storing temporary files. If <code>null</code>, the system's default will be used.
@return mixed The unserialized object.
|
getAsFile
|
php
|
craue/CraueFormFlowBundle
|
Storage/SerializableFile.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Storage/SerializableFile.php
|
MIT
|
private function setRequestStackOrSession($requestStackOrSession) : void {
// TODO accept only RequestStack as soon as Symfony >= 6.0 is required
if ($requestStackOrSession instanceof SessionInterface) {
$this->session = $requestStackOrSession;
return;
}
if ($requestStackOrSession instanceof RequestStack) {
$this->requestStack = $requestStackOrSession;
return;
}
throw new InvalidTypeException($requestStackOrSession, [RequestStack::class, SessionInterface::class]);
}
|
@param RequestStack|SessionInterface $requestStackOrSession
@throws InvalidTypeException
|
setRequestStackOrSession
|
php
|
craue/CraueFormFlowBundle
|
Storage/SessionProviderTrait.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Storage/SessionProviderTrait.php
|
MIT
|
public function __construct(TokenStorageInterface $tokenStorage, $requestStackOrSession) {
$this->tokenStorage = $tokenStorage;
$this->setRequestStackOrSession($requestStackOrSession);
}
|
@param TokenStorageInterface $tokenStorage
@param RequestStack|SessionInterface $requestStackOrSession
@throws InvalidTypeException
|
__construct
|
php
|
craue/CraueFormFlowBundle
|
Storage/UserSessionStorageKeyGenerator.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Storage/UserSessionStorageKeyGenerator.php
|
MIT
|
private function proceedToStep($stepNumber) {
static::$client->followRedirects();
$crawler = static::$client->request('GET', $this->url('_FormFlow_createTopic'));
if ($stepNumber < 2) {
return $crawler;
}
// bug report -> step 2
$form = $crawler->selectButton('next')->form();
$crawler = static::$client->submit($form, [
'createTopic[title]' => 'blah',
'createTopic[category]' => 'BUG_REPORT',
]);
if ($stepNumber < 3) {
return $crawler;
}
// comment -> step 3
$form = $crawler->selectButton('next')->form();
$crawler = static::$client->submit($form, [
'createTopic[comment]' => 'my comment',
]);
if ($stepNumber < 4) {
return $crawler;
}
// bug details -> step 4
$form = $crawler->selectButton('next')->form();
$crawler = static::$client->submit($form, [
'createTopic[details]' => 'blah blah',
]);
return $crawler;
}
|
Processes through the flow up to the given step by filling out the forms with some valid data.
@param int $stepNumber The targeted step number.
@return Crawler
|
proceedToStep
|
php
|
craue/CraueFormFlowBundle
|
Tests/CreateTopicFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/CreateTopicFlowTest.php
|
MIT
|
protected function getService($id) {
return static::getContainer()->get($id);
}
|
@param string $id The service identifier.
@return object The associated service.
|
getService
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function url($route, array $parameters = []) {
return $this->getService('router')->generate($route, $parameters);
}
|
@param string $route
@param array $parameters
@return string URL
|
url
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function assertCurrentStepNumber($expectedStepNumber, Crawler $crawler) {
$this->assertEquals($expectedStepNumber, $this->getNodeText('#step-number', $crawler));
}
|
@param int|string $expectedStepNumber
@param Crawler $crawler
|
assertCurrentStepNumber
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function assertCurrentFormData($expectedJson, Crawler $crawler) {
$this->assertEquals($expectedJson, $this->getNodeText('#form-data', $crawler));
}
|
@param string $expectedJson
@param Crawler $crawler
|
assertCurrentFormData
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function assertRenderedImageUrl($expectedSrcAttr, Crawler $crawler) {
$this->assertEquals($expectedSrcAttr, $this->getNodeAttribute('#rendered-image', 'src', $crawler));
}
|
@param string $expectedSrcAttr
@param Crawler $crawler
|
assertRenderedImageUrl
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function assertRenderedImageCollectionCount($expectedCount, Crawler $crawler) {
$this->assertEquals($expectedCount, $this->getNodeText('#rendered-images-count', $crawler));
}
|
@param int $expectedCount
@param Crawler $crawler
|
assertRenderedImageCollectionCount
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function assertContainsFormError($expectedError, Crawler $crawler) {
$this->assertStringContainsString($expectedError, $this->getNodeText('form', $crawler));
}
|
@param string $expectedError
@param Crawler $crawler
|
assertContainsFormError
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
protected function assertNotContainsFormError($unexpectedError, Crawler $crawler) {
$this->assertStringNotContainsString($unexpectedError, $this->getNodeText('form', $crawler));
}
|
@param string $unexpectedError
@param Crawler $crawler
|
assertNotContainsFormError
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
private function getNodeAttribute($selector, $attribute, Crawler $crawler) {
try {
return $crawler->filter($selector)->attr($attribute);
} catch (\InvalidArgumentException $e) {
$this->fail(sprintf("No node found for selector '%s'. Content:\n%s", $selector, static::$client->getResponse()->getContent()));
}
}
|
@param string $selector
@param string $attribute
@param Crawler $crawler
|
getNodeAttribute
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
private function getNodeText($selector, Crawler $crawler) {
try {
return $crawler->filter($selector)->text(null, true);
} catch (\InvalidArgumentException $e) {
$this->fail(sprintf("No node found for selector '%s'. Content:\n%s", $selector, static::$client->getResponse()->getContent()));
}
}
|
@param string $selector
@param Crawler $crawler
|
getNodeText
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestCase.php
|
MIT
|
public function testIssue149() {
$crawler = static::$client->request('GET', $this->url('_FormFlow_issue149'));
$this->assertSame(200, static::$client->getResponse()->getStatusCode());
$this->assertCurrentStepNumber(1, $crawler);
$this->assertCurrentFormData('{"photo":null}', $crawler);
// enter a title -> step 2
$form = $crawler->selectButton('next')->form();
$crawler = static::$client->submit($form, [
'issue149[photo][title]' => 'blue pixel',
]);
$this->assertCurrentStepNumber(2, $crawler);
$this->assertCurrentFormData('{"photo":{"image":null,"title":"blue pixel"}}', $crawler);
// next -> step 3
$form = $crawler->selectButton('next')->form();
$crawler = static::$client->submit($form);
$this->assertCurrentStepNumber(3, $crawler);
// ensure that the title is preserved
$this->assertCurrentFormData('{"photo":{"image":null,"title":"blue pixel"}}', $crawler);
}
|
The issue is caused by existence of a file field, regardless of actually uploading a file.
|
testIssue149
|
php
|
craue/CraueFormFlowBundle
|
Tests/Issue149Test.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Issue149Test.php
|
MIT
|
protected function getFlowWithMockedMethods(array $methodNames) {
return $this->getMockBuilder(FormFlow::class)->onlyMethods($methodNames)->getMock();
}
|
@param string[] $methodNames Names of methods to be mocked.
@return MockObject|FormFlow
|
getFlowWithMockedMethods
|
php
|
craue/CraueFormFlowBundle
|
Tests/UnitTestCase.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/UnitTestCase.php
|
MIT
|
public function testBcMethodDelegation_getCurrentStep() {
$flow = $this->getFlowWithMockedMethods(['getCurrentStepNumber']);
$flow
->expects($this->once())
->method('getCurrentStepNumber')
;
$flow->getCurrentStep();
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::getCurrentStep is deprecated since CraueFormFlowBundle 2.0. Use method getCurrentStepNumber instead.
|
testBcMethodDelegation_getCurrentStep
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_getCurrentStepDescription() {
$flow = $this->getFlowWithMockedMethods(['getCurrentStepLabel']);
$flow
->expects($this->once())
->method('getCurrentStepLabel')
;
$flow->getCurrentStepDescription();
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::getCurrentStepDescription is deprecated since CraueFormFlowBundle 2.0. Use method getCurrentStepLabel instead.
|
testBcMethodDelegation_getCurrentStepDescription
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_getMaxSteps() {
$flow = $this->getFlowWithMockedMethods(['getStepCount']);
$flow
->expects($this->once())
->method('getStepCount')
;
$flow->getMaxSteps();
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::getMaxSteps is deprecated since CraueFormFlowBundle 2.0. Use method getStepCount instead.
|
testBcMethodDelegation_getMaxSteps
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_getStepDescriptions() {
$flow = $this->getFlowWithMockedMethods(['getStepLabels']);
$flow
->expects($this->once())
->method('getStepLabels')
;
$flow->getStepDescriptions();
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::getStepDescriptions is deprecated since CraueFormFlowBundle 2.0. Use method getStepLabels instead.
|
testBcMethodDelegation_getStepDescriptions
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_getFirstStep() {
$flow = $this->getFlowWithMockedMethods(['getFirstStepNumber']);
$flow
->expects($this->once())
->method('getFirstStepNumber')
;
$flow->getFirstStep();
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::getFirstStep is deprecated since CraueFormFlowBundle 2.0. Use method getFirstStepNumber instead.
|
testBcMethodDelegation_getFirstStep
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_getLastStep() {
$flow = $this->getFlowWithMockedMethods(['getLastStepNumber']);
$flow
->expects($this->once())
->method('getLastStepNumber')
;
$flow->getLastStep();
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::getLastStep is deprecated since CraueFormFlowBundle 2.0. Use method getLastStepNumber instead.
|
testBcMethodDelegation_getLastStep
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_hasSkipStep() {
$flow = $this->getFlowWithMockedMethods(['isStepSkipped']);
$stepNumber = 1;
$flow
->expects($this->once())
->method('isStepSkipped')
->with($this->equalTo($stepNumber))
;
$flow->hasSkipStep($stepNumber);
}
|
@expectedDeprecation Method Craue\FormFlowBundle\Form\FormFlow::hasSkipStep is deprecated since CraueFormFlowBundle 2.0. Use method isStepSkipped instead.
|
testBcMethodDelegation_hasSkipStep
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowBcMethodsTest.php
|
MIT
|
public function testGetFormOptions_addGeneratedValidationGroup() {
$flow = $this->getFlowWithMockedMethods(['getName', 'loadStepsConfig']);
$flow
->expects($this->once())
->method('getName')
->will($this->returnValue('createTopic'))
;
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue([
[
'form_options' => [
'validation_groups' => 'Default',
]
],
]))
;
$options = $flow->getFormOptions(1);
$this->assertEquals(['flow_createTopic_step1', 'Default'], $options['validation_groups']);
}
|
Ensure that the generated step-based validation group is added.
|
testGetFormOptions_addGeneratedValidationGroup
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testGetFormOptions_setValidationGroups($validationGroups) {
$flow = $this->getFlowWithMockedMethods(['loadStepsConfig']);
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue([
[],
]))
;
$options = $flow->getFormOptions(1, [
'validation_groups' => $validationGroups,
]);
$this->assertSame($validationGroups, $options['validation_groups']);
}
|
Ensure that the "validation_groups" option can be set to specific valid values.
@dataProvider dataGetFormOptions_setValidationGroups
|
testGetFormOptions_setValidationGroups
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testGetFormOptions_generatedValidationGroupIsArray() {
$flow = $this->getFlowWithMockedMethods(['getName', 'loadStepsConfig']);
$flow
->expects($this->once())
->method('getName')
->will($this->returnValue('createTopic'))
;
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue([
[],
]))
;
$options = $flow->getFormOptions(1);
$this->assertEquals(['flow_createTopic_step1'], $options['validation_groups']);
}
|
Ensure that the generated step-based value for "validation_groups" is an array, which can be used to just add
other groups.
|
testGetFormOptions_generatedValidationGroupIsArray
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testGetFormOptions_considerGenericOptions() {
$flow = $this->getFlowWithMockedMethods(['loadStepsConfig']);
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue([
[],
]))
;
$flow->setGenericFormOptions([
'action' => 'targetUrl',
]);
$options = $flow->getFormOptions(1);
$this->assertEquals('targetUrl', $options['action']);
}
|
Ensure that generic options are considered.
|
testGetFormOptions_considerGenericOptions
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testGetFormOptions_considerStepSpecificOptions() {
$flow = $this->getFlowWithMockedMethods(['loadStepsConfig']);
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue([
[
'form_options' => [
'action' => 'specificTargetUrl',
]
],
]))
;
$flow->setGenericFormOptions([
'action' => 'targetUrl',
]);
$options = $flow->getFormOptions(1);
$this->assertEquals('specificTargetUrl', $options['action']);
}
|
Ensure that step specific options override generic options.
|
testGetFormOptions_considerStepSpecificOptions
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testGetFormOptions_considerDirectlyPassedOptions() {
$flow = $this->getFlowWithMockedMethods(['loadStepsConfig']);
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue([
[
'form_options' => [
'action' => 'specificTargetUrl',
]
],
]))
;
$flow->setGenericFormOptions([
'action' => 'targetUrl',
]);
$options = $flow->getFormOptions(1, [
'action' => 'finalTargetUrl',
]);
$this->assertEquals('finalTargetUrl', $options['action']);
}
|
Ensure that options can be overridden directly.
|
testGetFormOptions_considerDirectlyPassedOptions
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testGetRequestedStepNumber($httpMethod, $parameters, $dsnEnabled, $expectedStepNumber) {
$flow = $this->getFlowWithMockedMethods(['getName', 'getRequest']);
if ($dsnEnabled) {
$flow->setAllowDynamicStepNavigation(true);
}
$flow
->method('getName')
->will($this->returnValue('createTopic'))
;
$flow
->expects($this->once())
->method('getRequest')
->will($this->returnValue(Request::create('', $httpMethod, $parameters)))
;
$method = new \ReflectionMethod($flow, 'getRequestedStepNumber');
$method->setAccessible(true);
$this->assertSame($expectedStepNumber, $method->invoke($flow));
}
|
Ensure that the requested step number is correctly determined.
@dataProvider dataGetRequestedStepNumber
@param string $httpMethod The HTTP method.
@param array $parameters Parameters for the query/request.
@param bool $dsnEnabled If dynamic step navigation is enabled.
@param int $expectedStepNumber The expected step number being requested.
|
testGetRequestedStepNumber
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testIsValid($httpMethod, $parameters, $expectedValid) {
$flow = $this->getFlowWithMockedMethods(['getName', 'getRequest']);
$flow->setRevalidatePreviousSteps(false);
$flow
->method('getName')
->will($this->returnValue('createTopic'))
;
$flow
->method('getRequest')
->will($this->returnValue(Request::create('', $httpMethod, $parameters)))
;
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$factory = Forms::createFormFactoryBuilder()->getFormFactory();
$formBuilder = new FormBuilder(null, 'stdClass', $dispatcher, $factory);
$form = $formBuilder
->setCompound(true)
->setDataMapper($this->createMock(DataMapperInterface::class))
->add('aField', TextType::class)
->setMethod($httpMethod)
->setRequestHandler(new HttpFoundationRequestHandler())
->getForm()
;
$this->assertSame($expectedValid, $flow->isValid($form));
}
|
Ensure that the form is correctly considered valid.
@dataProvider dataIsValid
@param string $httpMethod The HTTP method.
@param array $parameters Parameters for the query/request.
@param bool $expectedValid If the form is expected to be valid.
|
testIsValid
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/FormFlowTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/FormFlowTest.php
|
MIT
|
public function testCreateFromConfig_bcOptionType() {
$step = Step::createFromConfig(1, [
'type' => 'myFormType',
]);
$this->assertEquals('myFormType', $step->getFormType());
}
|
@expectedDeprecation Step config option "type" is deprecated since CraueFormFlowBundle 3.0. Use "form_type" instead.
|
testCreateFromConfig_bcOptionType
|
php
|
craue/CraueFormFlowBundle
|
Tests/Form/StepBcTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Form/StepBcTest.php
|
MIT
|
public function testUseCorrectStorageImplementation() {
$storage = $this->getService('craue.form.flow.storage');
$expectedClass = empty($_ENV['DB_DSN']) ? SessionStorage::class : DoctrineStorage::class;
$this->assertInstanceOf($expectedClass, $storage);
}
|
Ensure that, depending on the configuration, the correct {@link StorageInterface} implementation is used.
This is useful because a compiler pass ({@link DoctrineStorageCompilerPass}) is needed to properly set up the
database connection and the storage service while relying on an DI extension to load the (overridden) service
may silently fail leading to a wrong implementation being used in tests.
|
testUseCorrectStorageImplementation
|
php
|
craue/CraueFormFlowBundle
|
Tests/IntegrationTestBundle/DependencyInjection/StorageImplementationTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/IntegrationTestBundle/DependencyInjection/StorageImplementationTest.php
|
MIT
|
protected function getFlowStub(array $stubbedMethods = [], ?array $stepsConfig = null) {
/* @var $flow MockObject|FormFlow */
$flow = $this->getMockBuilder(FormFlow::class)->onlyMethods(array_merge(['getName', 'loadStepsConfig'], $stubbedMethods))->getMock();
$flow->setDataManager(new DataManager(new SessionStorage(new Session(new MockArraySessionStorage()))));
$flow
->method('getName')
->will($this->returnValue('renderingTest'))
;
if ($stepsConfig === null) {
$stepsConfig = [
1 => [
'label' => 'step1',
],
2 => [
'label' => 'step2',
],
];
}
$flow
->expects($this->once())
->method('loadStepsConfig')
->will($this->returnValue($stepsConfig))
;
return $flow;
}
|
@param string[] $stubbedMethods names of additionally stubbed methods
@param array $stepsConfig steps config
@return MockObject|FormFlow
|
getFlowStub
|
php
|
craue/CraueFormFlowBundle
|
Tests/Resources/TemplateRenderingTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Resources/TemplateRenderingTest.php
|
MIT
|
public function testSaveLoad_file() : void {
if (\version_compare(\PHP_VERSION, '7.4', '<') && ($_ENV['DB_FLAVOR'] ?? '') === 'postgresql') {
$this->markTestSkipped('Would fail because SerializableFile::__serialize is only supported as of PHP 7.4.');
}
$session = new Session(new MockArraySessionStorage());
$session->setId('12345');
$request = Request::create('/');
$request->setSession($session);
$this->getService('request_stack')->push($request);
/** @var $dataManager DataManager */
$dataManager = $this->getService('craue.form.flow.data_manager');
$dataManager->dropAll();
$flow = $this->getFlow('testFlow', 'instance');
$imagePath = __DIR__ . '/../Fixtures/blue-pixel.png';
$imageFile = new UploadedFile($imagePath, basename($imagePath), 'image/png', null, true);
$dataIn = ['photo' => new SerializableFile($imageFile)];
$dataOut = ['photo' => $imageFile];
$dataManager->save($flow, $dataIn);
$this->assertEquals($dataOut, $dataManager->load($flow));
}
|
Ensure that a file uploaded within a flow is saved and restored correctly.
|
testSaveLoad_file
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/DataManagerIntegrationTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/DataManagerIntegrationTest.php
|
MIT
|
public function testLoad_emptyStorage() {
$createLocationFlow = $this->getFlow($this->createLocationFlowName, $this->createLocationFlowInstanceId);
$this->assertEquals([], $this->dataManager->load($createLocationFlow));
}
|
Ensure that even without any data an array is returned.
|
testLoad_emptyStorage
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/DataManagerTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/DataManagerTest.php
|
MIT
|
public function testListFlows_emptyStorage() {
$this->assertEquals([], $this->dataManager->listFlows());
}
|
Ensure that even without any data an array is returned.
|
testListFlows_emptyStorage
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/DataManagerTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/DataManagerTest.php
|
MIT
|
public function testListInstances_emptyStorage() {
$this->assertEquals([], $this->dataManager->listInstances('whatever'));
}
|
Ensure that even without any data an array is returned.
|
testListInstances_emptyStorage
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/DataManagerTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/DataManagerTest.php
|
MIT
|
protected function getFlow($name, $instanceId) {
$flow = $this->getFlowWithMockedMethods(['getName']);
$flow
->method('getName')
->will($this->returnValue($name))
;
$flow->setInstanceId($instanceId);
return $flow;
}
|
@param string $name
@param string $instanceId
@return MockObject|FormFlow
|
getFlow
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/DataManagerTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/DataManagerTest.php
|
MIT
|
public function testSetGet_stringsContainQuotes($key, $value) {
$this->storage->set($key, $value);
$this->assertSame($value, $this->storage->get($key));
}
|
Ensure that quoted data is properly handled by DBAL.
@dataProvider dataSetGet_stringsContainQuotes
|
testSetGet_stringsContainQuotes
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/DoctrineStorageTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/DoctrineStorageTest.php
|
MIT
|
private function getNewUploadedFile($document, $originalName, $mimeType = null) {
return new UploadedFile($document, $originalName, $mimeType, null, true);
}
|
@param string $document
@param string $originalName
@param string|null $mimeType
@return UploadedFile
|
getNewUploadedFile
|
php
|
craue/CraueFormFlowBundle
|
Tests/Storage/SerializableFileTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Storage/SerializableFileTest.php
|
MIT
|
public function testBcMethodDelegation_addDynamicStepNavigationParameter() {
$extension = $this->getMockBuilder(FormFlowExtension::class)->onlyMethods(['addDynamicStepNavigationParameters'])->getMock();
$parameters = ['foo' => 'bar'];
$flow = $this->getMockedFlow();
$stepNumber = 1;
$extension
->expects($this->once())
->method('addDynamicStepNavigationParameters')
->with($this->equalTo($parameters), $this->equalTo($flow), $this->equalTo($stepNumber))
;
$extension->addDynamicStepNavigationParameter($parameters, $flow, $stepNumber);
}
|
@expectedDeprecation Twig filter craue_addDynamicStepNavigationParameter is deprecated since CraueFormFlowBundle 3.0. Use filter craue_addDynamicStepNavigationParameters instead.
|
testBcMethodDelegation_addDynamicStepNavigationParameter
|
php
|
craue/CraueFormFlowBundle
|
Tests/Twig/Extension/FormFlowExtensionBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Twig/Extension/FormFlowExtensionBcMethodsTest.php
|
MIT
|
public function testBcMethodDelegation_removeDynamicStepNavigationParameter() {
$extension = $this->getMockBuilder(FormFlowExtension::class)->onlyMethods(['removeDynamicStepNavigationParameters'])->getMock();
$parameters = ['foo' => 'bar'];
$flow = $this->getMockedFlow();
$extension
->expects($this->once())
->method('removeDynamicStepNavigationParameters')
->with($this->equalTo($parameters), $this->equalTo($flow))
;
$extension->removeDynamicStepNavigationParameter($parameters, $flow);
}
|
@expectedDeprecation Twig filter craue_removeDynamicStepNavigationParameter is deprecated since CraueFormFlowBundle 3.0. Use filter craue_removeDynamicStepNavigationParameters instead.
|
testBcMethodDelegation_removeDynamicStepNavigationParameter
|
php
|
craue/CraueFormFlowBundle
|
Tests/Twig/Extension/FormFlowExtensionBcMethodsTest.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Tests/Twig/Extension/FormFlowExtensionBcMethodsTest.php
|
MIT
|
public function addDynamicStepNavigationParameters(array $parameters, FormFlow $flow, $stepNumber) {
return $this->formFlowUtil->addRouteParameters($parameters, $flow, $stepNumber);
}
|
Adds route parameters for dynamic step navigation.
@param array $parameters Current route parameters.
@param FormFlow $flow The flow involved.
@param int $stepNumber Number of the step the link will be generated for.
@return array Route parameters plus instance and step parameter.
|
addDynamicStepNavigationParameters
|
php
|
craue/CraueFormFlowBundle
|
Twig/Extension/FormFlowExtension.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Twig/Extension/FormFlowExtension.php
|
MIT
|
public function removeDynamicStepNavigationParameters(array $parameters, FormFlow $flow) {
return $this->formFlowUtil->removeRouteParameters($parameters, $flow);
}
|
Removes route parameters for dynamic step navigation.
@param array $parameters Current route parameters.
@param FormFlow $flow The flow involved.
@return array Route parameters without instance and step parameter.
|
removeDynamicStepNavigationParameters
|
php
|
craue/CraueFormFlowBundle
|
Twig/Extension/FormFlowExtension.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Twig/Extension/FormFlowExtension.php
|
MIT
|
public function isStepLinkable(FormFlow $flow, $stepNumber) {
if (!$flow->isAllowDynamicStepNavigation()
|| $flow->getCurrentStepNumber() === $stepNumber
|| $flow->isStepSkipped($stepNumber)) {
return false;
}
$lastStepConsecutivelyDone = 0;
for ($i = $flow->getFirstStepNumber(), $lastStepNumber = $flow->getLastStepNumber(); $i < $lastStepNumber; ++$i) {
if ($flow->isStepDone($i)) {
$lastStepConsecutivelyDone = $i;
} else {
break;
}
}
$lastStepLinkable = $lastStepConsecutivelyDone + 1;
if ($stepNumber <= $lastStepLinkable) {
return true;
}
return false;
}
|
@param FormFlow $flow The flow involved.
@param int $stepNumber Number of the step the link will be generated for.
@return bool If the step can be linked to.
|
isStepLinkable
|
php
|
craue/CraueFormFlowBundle
|
Twig/Extension/FormFlowExtension.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Twig/Extension/FormFlowExtension.php
|
MIT
|
public function addRouteParameters(array $parameters, FormFlow $flow, $stepNumber = null) {
if ($stepNumber === null) {
$stepNumber = $flow->getCurrentStepNumber();
}
$parameters[$flow->getDynamicStepNavigationInstanceParameter()] = $flow->getInstanceId();
$parameters[$flow->getDynamicStepNavigationStepParameter()] = $stepNumber;
return $parameters;
}
|
Adds route parameters for dynamic step navigation.
@param array $parameters Current route parameters.
@param FormFlow $flow The flow involved.
@param int|null $stepNumber Number of the step the link will be generated for. If <code>null</code>, the <code>$flow</code>'s current step number will be used.
@return array Route parameters plus instance and step parameter.
|
addRouteParameters
|
php
|
craue/CraueFormFlowBundle
|
Util/FormFlowUtil.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Util/FormFlowUtil.php
|
MIT
|
public function removeRouteParameters(array $parameters, FormFlow $flow) {
unset($parameters[$flow->getDynamicStepNavigationInstanceParameter()]);
unset($parameters[$flow->getDynamicStepNavigationStepParameter()]);
return $parameters;
}
|
Removes route parameters for dynamic step navigation.
@param array $parameters Current route parameters.
@param FormFlow $flow The flow involved.
@return array Route parameters without instance and step parameter.
|
removeRouteParameters
|
php
|
craue/CraueFormFlowBundle
|
Util/FormFlowUtil.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Util/FormFlowUtil.php
|
MIT
|
public static function isRandomString($input, $length) {
if (!is_string($input)) {
throw new InvalidTypeException($input, 'string');
}
if (!is_int($length)) {
throw new InvalidTypeException($length, 'int');
}
if ($length < 0) {
throw new \InvalidArgumentException(sprintf('Length must be >= 0, "%s" given.', $length));
}
return preg_match(sprintf('/^[a-zA-Z0-9-_]{%u}$/', $length), $input) === 1;
}
|
@param string $input
@param int $length
@return bool
|
isRandomString
|
php
|
craue/CraueFormFlowBundle
|
Util/StringUtil.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Util/StringUtil.php
|
MIT
|
public static function fqcnToFlowName($fqcn) {
if (!is_string($fqcn)) {
throw new InvalidTypeException($fqcn, 'string');
}
if (preg_match('/([^\\\\]+?)(flow)?$/i', $fqcn, $matches)) {
return lcfirst(preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1\\2', $matches[1]));
}
return null;
}
|
@param string $fqcn FQCN
@return string|null flow name or null if not a FQCN
|
fqcnToFlowName
|
php
|
craue/CraueFormFlowBundle
|
Util/StringUtil.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Util/StringUtil.php
|
MIT
|
public static function addTempFile($tempFile) {
self::$tempFiles[] = $tempFile;
}
|
@param string $tempFile Path to a file.
|
addTempFile
|
php
|
craue/CraueFormFlowBundle
|
Util/TempFileUtil.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Util/TempFileUtil.php
|
MIT
|
public static function removeTempFiles() {
foreach (self::$tempFiles as $tempFile) {
if (is_file($tempFile)) {
@unlink($tempFile);
}
}
self::$tempFiles = [];
}
|
Removes all previously added files from disk.
|
removeTempFiles
|
php
|
craue/CraueFormFlowBundle
|
Util/TempFileUtil.php
|
https://github.com/craue/CraueFormFlowBundle/blob/master/Util/TempFileUtil.php
|
MIT
|
public function __construct(
PersistenceRepositoryInterface $persistences,
UserRepositoryInterface $users,
RoleRepositoryInterface $roles,
ActivationRepositoryInterface $activations,
Dispatcher $dispatcher
) {
$this->users = $users;
$this->roles = $roles;
$this->dispatcher = $dispatcher;
$this->activations = $activations;
$this->persistences = $persistences;
}
|
Constructor.
@param \Cartalyst\Sentinel\Persistences\PersistenceRepositoryInterface $persistences
@param \Cartalyst\Sentinel\Users\UserRepositoryInterface $users
@param \Cartalyst\Sentinel\Roles\RoleRepositoryInterface $roles
@param \Cartalyst\Sentinel\Activations\ActivationRepositoryInterface $activations
@param \Illuminate\Contracts\Events\Dispatcher $dispatcher
@return void
|
__construct
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function register(array $credentials, $callback = false)
{
if (! $callback instanceof Closure && ! is_bool($callback)) {
throw new InvalidArgumentException('You must provide a closure or a boolean.');
}
$this->fireEvent('sentinel.registering', [$credentials]);
$valid = $this->users->validForCreation($credentials);
if (! $valid) {
return false;
}
$argument = $callback instanceof Closure ? $callback : null;
$user = $this->users->create($credentials, $argument);
if ($callback === true) {
$this->activate($user);
}
$this->fireEvent('sentinel.registered', $user);
return $user;
}
|
Registers a user. You may provide a callback to occur before the user
is saved, or provide a true boolean as a shortcut to activation.
@param array $credentials
@param bool|\Closure $callback
@throws \InvalidArgumentException
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
register
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function registerAndActivate(array $credentials)
{
return $this->register($credentials, true);
}
|
Registers and activates the user.
@param array $credentials
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
registerAndActivate
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function activate($user): bool
{
if (is_string($user) || is_array($user)) {
$users = $this->getUserRepository();
$method = 'findBy'.(is_string($user) ? 'Id' : 'Credentials');
$user = $users->{$method}($user);
}
if (! $user instanceof UserInterface) {
throw new InvalidArgumentException('No valid user was provided.');
}
$this->fireEvent('sentinel.activating', $user);
$activations = $this->getActivationRepository();
$activation = $activations->create($user);
$this->fireEvent('sentinel.activated', [$user, $activation]);
return $activations->complete($user, $activation->getCode());
}
|
Activates the given user.
@param mixed $user
@throws \InvalidArgumentException
@return bool
|
activate
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function check()
{
if ($this->user !== null) {
return $this->user;
}
if (! $code = $this->persistences->check()) {
return false;
}
if (! $user = $this->persistences->findUserByPersistenceCode($code)) {
return false;
}
if (! $this->cycleCheckpoints('check', $user)) {
return false;
}
return $this->user = $user;
}
|
Checks to see if a user is logged in.
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
check
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function forceCheck()
{
return $this->bypassCheckpoints(function ($sentinel) {
return $sentinel->check();
});
}
|
Checks to see if a user is logged in, bypassing checkpoints.
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
forceCheck
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function guest(): bool
{
return ! $this->check();
}
|
Checks if we are currently a guest.
@return bool
|
guest
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function authenticate($credentials, bool $remember = false, bool $login = true)
{
$response = $this->fireEvent('sentinel.authenticating', [$credentials], true);
if ($response === false) {
return false;
}
if ($credentials instanceof UserInterface) {
$user = $credentials;
} else {
$user = $this->users->findByCredentials($credentials);
$valid = $user !== null ? $this->users->validateCredentials($user, $credentials) : false;
if (! $valid) {
$this->cycleCheckpoints('fail', $user, false);
return false;
}
}
if (! $this->cycleCheckpoints('login', $user)) {
return false;
}
if ($login) {
if (! $user = $this->login($user, $remember)) {
return false;
}
}
$this->fireEvent('sentinel.authenticated', $user);
return $this->user = $user;
}
|
Authenticates a user, with "remember" flag.
@param array|\Cartalyst\Sentinel\Users\UserInterface $credentials
@param bool $remember
@param bool $login
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
authenticate
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function authenticateAndRemember($credentials)
{
return $this->authenticate($credentials, true);
}
|
Authenticates a user, with the "remember" flag.
@param array|\Cartalyst\Sentinel\Users\UserInterface $credentials
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
authenticateAndRemember
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function forceAuthenticate($credentials, bool $remember = false)
{
return $this->bypassCheckpoints(function ($sentinel) use ($credentials, $remember) {
return $sentinel->authenticate($credentials, $remember);
});
}
|
Forces an authentication to bypass checkpoints.
@param array|\Cartalyst\Sentinel\Users\UserInterface $credentials
@param bool $remember
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
forceAuthenticate
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function forceAuthenticateAndRemember($credentials)
{
return $this->forceAuthenticate($credentials, true);
}
|
Forces an authentication to bypass checkpoints, with the "remember" flag.
@param array|\Cartalyst\Sentinel\Users\UserInterface $credentials
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
forceAuthenticateAndRemember
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function stateless($credentials)
{
return $this->authenticate($credentials, false, false);
}
|
Attempt a stateless authentication.
@param array|\Cartalyst\Sentinel\Users\UserInterface $credentials
@return bool|\Cartalyst\Sentinel\Users\UserInterface
|
stateless
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function basic()
{
$credentials = $this->getRequestCredentials();
// We don't really want to add a throttling record for the
// first failed login attempt, which actually occurs when
// the user first hits a protected route.
if ($credentials === null) {
return $this->getBasicResponse();
}
$user = $this->stateless($credentials);
if ($user) {
return;
}
return $this->getBasicResponse();
}
|
Attempt to authenticate using HTTP Basic Auth.
@return mixed
|
basic
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function getRequestCredentials(): ?array
{
if ($this->requestCredentials === null) {
$this->requestCredentials = function () {
$credentials = [];
if (isset($_SERVER['PHP_AUTH_USER'])) {
$credentials['login'] = $_SERVER['PHP_AUTH_USER'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$credentials['password'] = $_SERVER['PHP_AUTH_PW'];
}
if (count($credentials) > 0) {
return $credentials;
}
};
}
$credentials = $this->requestCredentials;
return $credentials();
}
|
Returns the request credentials.
@return array|null
|
getRequestCredentials
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
public function setRequestCredentials(Closure $requestCredentials): void
{
$this->requestCredentials = $requestCredentials;
}
|
Sets the closure which resolves the request credentials.
@param \Closure $requestCredentials
@return void
|
setRequestCredentials
|
php
|
cartalyst/sentinel
|
src/Sentinel.php
|
https://github.com/cartalyst/sentinel/blob/master/src/Sentinel.php
|
BSD-3-Clause
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.