- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 105
feat: behat support #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            kbond
  wants to merge
  3
  commits into
  zenstruck:1.x
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
kbond:behat
  
      
      
   
  
    
  
  
  
 
  
      
    base: 1.x
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    feat: behat support #378
Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /composer.lock | ||
| /phpunit.xml | ||
| /phpunit-dama-doctrine.xml | ||
| /behat.yml | ||
| /vendor/ | ||
| /bin/tools/*/vendor/ | ||
| /build/ | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| default: | ||
| suites: | ||
| default: | ||
| contexts: | ||
| - Zenstruck\Foundry\Tests\Behat\TestContext | ||
| - Zenstruck\Foundry\Test\Behat\FactoriesContext | ||
| extensions: | ||
| FriendsOfBehat\SymfonyExtension: | ||
| kernel: | ||
| class: Zenstruck\Foundry\Tests\Fixtures\Kernel | ||
| bootstrap: tests/bootstrap.php | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Feature: Foundry | ||
| Scenario: Ensure can create factories | ||
| Given there is 1 category | ||
| Then there is 1 category in the database | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|  | ||
| namespace Zenstruck\Foundry\Test\Behat; | ||
|  | ||
| use Behat\Behat\Context\Context; | ||
| use Psr\Container\ContainerInterface; | ||
| use Zenstruck\Foundry\ChainManagerRegistry; | ||
| use Zenstruck\Foundry\Factory; | ||
| use Zenstruck\Foundry\Test\LazyManagerRegistry; | ||
| use Zenstruck\Foundry\Test\TestState; | ||
|  | ||
| /** | ||
| * @author Kevin Bond <[email protected]> | ||
| */ | ||
| final class FactoriesContext implements Context | ||
| { | ||
| public function __construct(private ContainerInterface $container) | ||
| { | ||
| } | ||
|  | ||
| /** | ||
| * @BeforeScenario | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These annotations cause race conditions because you cannot guarantee when they are run... hence why I think subscriber is the way to go. | ||
| */ | ||
| public function setUpFactories(): void | ||
| { | ||
| TestState::bootFromContainer($this->container); | ||
| Factory::configuration()->setManagerRegistry( | ||
| new LazyManagerRegistry(function (): ChainManagerRegistry { | ||
| return TestState::initializeChainManagerRegistry($this->container); | ||
| }) | ||
| ); | ||
| } | ||
|  | ||
| /** | ||
| * @AfterScenario | ||
| */ | ||
| public function tearDownFactories(): void | ||
| { | ||
| TestState::shutdownFoundry(); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|  | ||
| namespace Zenstruck\Foundry\Test\Behat; | ||
|  | ||
| use Behat\Behat\Context\Context; | ||
| use Psr\Container\ContainerInterface; | ||
| use Zenstruck\Foundry\Test\DatabaseResetter; | ||
|  | ||
| /** | ||
| * @author Kevin Bond <[email protected]> | ||
| */ | ||
| final class ResetDatabaseContext implements Context | ||
| { | ||
| public function __construct(private ContainerInterface $container) | ||
| { | ||
| } | ||
|  | ||
| /** | ||
| * @BeforeSuite | ||
| */ | ||
| public function resetDatabase(): void | ||
| { | ||
| DatabaseResetter::resetDatabase($this->container->get('kernel')); | ||
| } | ||
|  | ||
| /** | ||
| * @BeforeScenario | ||
| */ | ||
| public function resetSchema(): void | ||
| { | ||
| DatabaseResetter::resetSchema($this->container->get('kernel')); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|  | ||
| namespace Zenstruck\Foundry\Tests\Behat; | ||
|  | ||
| use Behat\Behat\Context\Context; | ||
| use Zenstruck\Foundry\Tests\Fixtures\Factories\CategoryFactory; | ||
|  | ||
| /** | ||
| * @author Kevin Bond <[email protected]> | ||
| */ | ||
| final class TestContext implements Context | ||
| { | ||
| /** | ||
| * @Given there is :count category | ||
| */ | ||
| public function thereIsCategory(int $count): void | ||
| { | ||
| CategoryFactory::createMany($count); | ||
| } | ||
|  | ||
| /** | ||
| * @Then there is :count category in the database | ||
| */ | ||
| public function thereIsCategoryInTheDatabase(int $count): void | ||
| { | ||
| CategoryFactory::assert()->count($count); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need some help figuring out why this doesn't seem to be working. When I run
vendor/bin/behatI get the following error:I've confirmed the kernel isn't being booted but not sure why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is to do with this: src/Listener/KernelOrchestrator.php:tearDown in symfony extension...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its loaded in the service extension here:
\FriendsOfBehat\SymfonyExtension\ServiceContainer\SymfonyExtension::loadKernelRebooter
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably try to restructure the new foundry behat contexts in this PR as a listener (like KernelOrchestrator) and perhaps try to use the priority (int) on the subscribed callbacks (e.g. 16 or something) to trigger database/foundry registry reset. Ive found it possible to induce memory leaks quite easily or race conditions in a few integrations ive attempted previously.