Skip to content

Commit

Permalink
no longer use annotations for test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Aug 24, 2023
1 parent ba3c716 commit 99891a6
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 73 deletions.
48 changes: 0 additions & 48 deletions Tests/IntegrationTestBundle/Controller/FormFlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Twig\Environment;

/**
Expand All @@ -54,116 +53,69 @@ public function __construct(FormFlowUtil $formFlowUtil, Environment $twig) {
$this->twig = $twig;
}

/**
* @Route("/create-topic/", name="_FormFlow_createTopic")
*/
public function createTopicAction(Request $request, CreateTopicFlow $flow) {
return $this->processFlow($request, new Topic(), $flow);
}

/**
* @Route("/create-topic-redirect-after-submit/", name="_FormFlow_createTopic_redirectAfterSubmit")
*/
public function createTopicRedirectAfterSubmitAction(Request $request, CreateTopicFlow $flow) {
$flow->setAllowDynamicStepNavigation(false);
$flow->setAllowRedirectAfterSubmit(true);

return $this->processFlow($request, new Topic(), $flow);
}

/**
* @Route("/create-vehicle/", name="_FormFlow_createVehicle")
*/
public function createVehicleAction(Request $request, CreateVehicleFlow $flow) {
return $this->processFlow($request, new Vehicle(), $flow);
}

/**
* @Route("/demo1/", name="_FormFlow_demo1")
*/
public function demo1Action(Request $request, Demo1Flow $flow) {
return $this->processFlow($request, new \stdClass(), $flow);
}

/**
* @Route("/issue64/", name="_FormFlow_issue64")
*/
public function issue64Action(Request $request, Issue64Flow $flow) {
return $this->processFlow($request, new Issue64Data(), $flow);
}

/**
* No trailing slash here to add the step only when needed.
* @Route("/issue87/{step}", defaults={"step"=1}, name="_FormFlow_issue87")
*/
public function issue87Action(Request $request, Issue87Flow $flow) {
return $this->processFlow($request, new \stdClass(), $flow);
}

/**
* @Route("/issue149/", name="_FormFlow_issue149")
*/
public function issue149Action(Request $request, Issue149Flow $flow) {
return $this->processFlow($request, new Issue149Data(), $flow);
}

/**
* @Route("/issue303/", name="_FormFlow_issue303")
*/
public function issue303Action(Request $request, Issue303Flow $flow) {
return $this->processFlow($request, new \stdClass(), $flow);
}

/**
* @Route("/revalidatePreviousSteps/enabled/", defaults={"enabled"=true}, name="_FormFlow_revalidatePreviousSteps_enabled")
* @Route("/revalidatePreviousSteps/disabled/", defaults={"enabled"=false}, name="_FormFlow_revalidatePreviousSteps_disabled")
*/
public function revalidatePreviousStepsAction(Request $request, RevalidatePreviousStepsFlow $flow, $enabled) {
$flow->setRevalidatePreviousSteps($enabled);

return $this->processFlow($request, new RevalidatePreviousStepsData(), $flow);
}

/**
* @Route("/skipFirstStepUsingClosure/", name="_FormFlow_skipFirstStepUsingClosure")
*/
public function skipFirstStepUsingClosureAction(Request $request, SkipFirstStepUsingClosureFlow $flow) {
return $this->processFlow($request, new \stdClass(), $flow);
}

/**
* @Route("/removeSecondStepSkipMarkOnReset/", name="_FormFlow_removeSecondStepSkipMarkOnReset")
*/
public function removeSecondStepSkipMarkOnResetAction(Request $request, RemoveSecondStepSkipMarkOnResetFlow $flow) {
return $this->processFlow($request, new \stdClass(), $flow);
}

/**
* @Route("/onlyOneStep/", name="_FormFlow_onlyOneStep")
*/
public function onlyOneStepAction(Request $request, OnlyOneStepFlow $flow) {
return $this->processFlow($request, new \stdClass(), $flow);
}

/**
* @Route("/photoUpload/", name="_FormFlow_photoUpload")
*/
public function photoUploadAction(Request $request, PhotoUploadFlow $flow) {
return $this->processFlow($request, new PhotoUpload(), $flow,
'@IntegrationTest/FormFlow/photoUpload.html.twig');
}

/**
* @Route("/photoCollectionUpload/", name="_FormFlow_photoCollectionUpload")
*/
public function photoCollectionUploadAction(Request $request, PhotoCollectionUploadFlow $flow) {
return $this->processFlow($request, new PhotoCollection(), $flow,
'@IntegrationTest/FormFlow/photoCollectionUpload.html.twig');
}

/**
* @Route("/usualForm/", name="_FormFlow_usualForm")
*/
public function usualFormAction(Request $request, CreateTopicFlow $flow, FormFactoryInterface $formFactory) {
return $this->processFlow($request, new Topic(), $flow,
'@IntegrationTest/FormFlow/usualForm.html.twig', ['usualForm' => $formFactory->create()->createView()]);
Expand Down
6 changes: 5 additions & 1 deletion Tests/IntegrationTestBundle/Entity/Issue149Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -13,8 +14,11 @@ class Issue149Data {

/**
* @var Issue149SubData
* @Assert\Valid(groups={"flow_issue149_step1"})
*/
public $photo;

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addPropertyConstraint('photo', new Assert\Valid(['groups' => 'flow_issue149_step1']));
}

}
8 changes: 6 additions & 2 deletions Tests/IntegrationTestBundle/Entity/Issue64Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -13,9 +14,12 @@ class Issue64Data {

/**
* @var Issue64SubData
* @Assert\NotNull(groups={"flow_issue64_step1", "flow_issue64_step2", "flow_issue64_step3"})
* @Assert\Valid(groups={"flow_issue64_step1", "flow_issue64_step2", "flow_issue64_step3"})
*/
public $sub;

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addPropertyConstraint('sub', new Assert\NotNull(['groups' => ['flow_issue64_step1', 'flow_issue64_step2', 'flow_issue64_step3']]));
$metadata->addPropertyConstraint('sub', new Assert\Valid(['groups' => ['flow_issue64_step1', 'flow_issue64_step2', 'flow_issue64_step3']]));
}

}
8 changes: 6 additions & 2 deletions Tests/IntegrationTestBundle/Entity/Issue64SubData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -13,14 +14,17 @@ class Issue64SubData {

/**
* @var string
* @Assert\NotBlank(groups={"flow_issue64_step1"})
*/
public $prop1;

/**
* @var string
* @Assert\NotBlank(groups={"flow_issue64_step2"})
*/
public $prop2;

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addPropertyConstraint('prop1', new Assert\NotBlank(['groups' => 'flow_issue64_step1']));
$metadata->addPropertyConstraint('prop2', new Assert\NotBlank(['groups' => 'flow_issue64_step2']));
}

}
8 changes: 6 additions & 2 deletions Tests/IntegrationTestBundle/Entity/PhotoUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -14,8 +15,6 @@ class PhotoUpload {

/**
* @var UploadedFile
* @Assert\NotNull(groups={"flow_photoUpload_step1"})
* @Assert\Image(groups={"flow_photoUpload_step1"})
*/
public $photo;

Expand All @@ -32,4 +31,9 @@ public function getPhotoMimeType() {
return $this->photo->getMimeType();
}

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addPropertyConstraint('photo', new Assert\NotNull(['groups' => 'flow_photoUpload_step1']));
$metadata->addPropertyConstraint('photo', new Assert\Image(['groups' => 'flow_photoUpload_step1']));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -18,14 +19,15 @@ public static function resetValidationCalls() {
self::$validationCalls = 0;
}

/**
* @Assert\Callback(groups={"flow_revalidatePreviousSteps_step1"})
*/
public function isDataValid(ExecutionContextInterface $context) {
// valid only on first call
if (++self::$validationCalls > 1) {
$context->addViolation('Take this!');
}
}

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addConstraint(new Assert\Callback('isDataValid', null, null, ['groups' => 'flow_revalidatePreviousSteps_step1']));
}

}
12 changes: 8 additions & 4 deletions Tests/IntegrationTestBundle/Entity/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -13,7 +14,6 @@ class Topic {

/**
* @var string
* @Assert\NotBlank(groups={"flow_createTopic_step1"})
*/
public $title;

Expand All @@ -24,8 +24,6 @@ class Topic {

/**
* @var string
* @Assert\Choice(callback="getValidCategories", groups={"flow_createTopic_step1"}, strict=true)
* @Assert\NotBlank(groups={"flow_createTopic_step1"})
*/
public $category;

Expand All @@ -36,7 +34,6 @@ class Topic {

/**
* @var string
* @Assert\NotBlank(groups={"flow_createTopic_step3"})
*/
public $details;

Expand All @@ -52,4 +49,11 @@ public static function getValidCategories() {
];
}

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addPropertyConstraint('title', new Assert\NotBlank(['groups' => 'flow_createTopic_step1']));
$metadata->addPropertyConstraint('category', new Assert\Choice(['groups' => 'flow_createTopic_step1', 'callback' => 'getValidCategories', 'strict' => true]));
$metadata->addPropertyConstraint('category', new Assert\NotBlank(['groups' => 'flow_createTopic_step1']));
$metadata->addPropertyConstraint('details', new Assert\NotBlank(['groups' => 'flow_createTopic_step3']));
}

}
8 changes: 6 additions & 2 deletions Tests/IntegrationTestBundle/Entity/Vehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -13,18 +14,21 @@ class Vehicle {

/**
* @var int
* @Assert\NotBlank(groups={"flow_createVehicle_step1"})
*/
public $numberOfWheels;

/**
* @var string
* @Assert\NotBlank(groups={"flow_createVehicle_step2"})
*/
public $engine;

public function canHaveEngine() {
return $this->numberOfWheels === 4;
}

public static function loadValidatorMetadata(ClassMetadata $metadata) : void {
$metadata->addPropertyConstraint('numberOfWheels', new Assert\NotBlank(['groups' => 'flow_createVehicle_step1']));
$metadata->addPropertyConstraint('engine', new Assert\NotBlank(['groups' => 'flow_createVehicle_step2']));
}

}
6 changes: 1 addition & 5 deletions Tests/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ imports:
- { resource: '@IntegrationTestBundle/Resources/config/controller.xml' }
- { resource: parameters.php }
- { resource: config_hacks.php }
# workaround for symfony/framework-bundle not loading its annotations config when doctrine/annotations is installed only as a dev dependency
- { resource: '@FrameworkBundle/Resources/config/annotations.*' }

framework:
csrf_protection: ~
form: ~
router:
resource: '%kernel.project_dir%/Tests/config/routing.yml'
resource: '%kernel.project_dir%/Tests/config/routes.php'
secret: whatever
session:
handler_id: ~
test: ~
translator:
fallback: en
validation:
enable_annotations: true

security:
providers:
Expand Down

0 comments on commit 99891a6

Please sign in to comment.