Skip to content
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

Start using arcus-software/concrete-php-assert as my Assertion Library in Behat tests #2

Closed
john-arcus opened this issue Apr 26, 2018 · 3 comments

Comments

@john-arcus
Copy link
Owner

john-arcus commented Apr 26, 2018

Goal

Start using arcus-software/concrete-php-assert as my Assertion Library in Behat tests

Why

I was getting real tired of typing the full name of the PHPUnit class to invoke assertion methods in my Behat /features/bootstrap/FeatureContext.php script like:

PHPUnit\Framework\Assert::assertTrue( $foo );

I wanted to create one instance of the assertion library in the constructor. But, I couldn't create an instance of the Assert class because it was an abstract class.

So, I wrote a package which simply extended that Assert class as a concrete class which could be instantiated.

Note: During the process I learned that you could use PHP Namespace aliases. So, perhaps the package is unnecessary. But, now I have written it, I may as well try it out and use it.

How

Follow the instructions on the arcus-software/concrete-php-assert README page > Using ConcreteAssert in your own project.

@john-arcus
Copy link
Owner Author

Let's navigate to the root of my project and run the composer require command as per the instructions.

$ pwd
/Users/jw/Documents/Projects/PackageDev/xandria-demo
$ composer require --dev arcus-software/concrete-php-assert
Using version ^0.0.3 for arcus-software/concrete-php-assert
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing arcus-software/concrete-php-assert (v0.0.3): Downloading (100%)         
Writing lock file
Generating autoload files

That seems OK.

@john-arcus
Copy link
Owner Author

Now let's check to see my Behat tests are acutally running as good as can be afore I go a-meddling with it.

$ pwd
/Users/jw/Documents/Projects/PackageDev/xandria-demo
$ vendor/bin/behat
Feature: Quick Start to see demo in action.
  In order to encourage speedy use and understanding of the Xandria library
  As a PHP developer who is new to the project
  I can see the demo code working with least amount of effort on my part.
  
  It is a common courtesy to make it easy for newcomers. Any project that exposes the ethos that they value contributors
  and make the effort to welcome them will get more supporters.

  Scenario: Launching the environment.                                            # features/quickstart.feature:10
    Given I have installed the project                                            # FeatureContext::iHaveInstalledTheProject()
    And I have Vagrant and a virtualization product installed on my host machine  # FeatureContext::iHaveVagrantAndAVirtualizationProductInstalledOnMyHostMachine()
    When I run `vagrant up` in the root of the project                            # FeatureContext::iRunVagrantUpInTheRootOfTheProject()
      TODO: write pending definition
    Then vagrant provisions and launches a Homestead Improved virtual environment # FeatureContext::vagrantProvisionsAndLaunchesAHomesteadImprovedVirtualEnvironment()

  Scenario: Run the demo code to prove it works.                                                # features/quickstart.feature:16
    Given I have installed the project                                                          # FeatureContext::iHaveInstalledTheProject()
    When I run the command to run the project's quickstart.php script                           # FeatureContext::iRunTheCommandToRunTheProjectsQuickstartPhpScript()
    Then The expected output is written to STDOUT to prove that the project code is working OK. # FeatureContext::theExpectedOutputIsWrittenToStdoutToProveThatTheProjectCodeIsWorkingOk()

2 scenarios (1 passed, 1 pending)
7 steps (5 passed, 1 pending, 1 skipped)
0m0.42s (7.65Mb)

@john-arcus
Copy link
Owner Author

That's ok.

Now let's replace my usage of PHPUnit\Framework\Assert with the new concrete version.

Done.

Let's test it works before I commit the changes...

$ vendor/bin/behat
Feature: Quick Start to see demo in action.
  In order to encourage speedy use and understanding of the Xandria library
  As a PHP developer who is new to the project
  I can see the demo code working with least amount of effort on my part.
  
  It is a common courtesy to make it easy for newcomers. Any project that exposes the ethos that they value contributors
  and make the effort to welcome them will get more supporters.

  Scenario: Launching the environment.                                            # features/quickstart.feature:10
    Given I have installed the project                                            # FeatureContext::iHaveInstalledTheProject()
    And I have Vagrant and a virtualization product installed on my host machine  # FeatureContext::iHaveVagrantAndAVirtualizationProductInstalledOnMyHostMachine()
    When I run `vagrant up` in the root of the project                            # FeatureContext::iRunVagrantUpInTheRootOfTheProject()
      TODO: write pending definition
    Then vagrant provisions and launches a Homestead Improved virtual environment # FeatureContext::vagrantProvisionsAndLaunchesAHomesteadImprovedVirtualEnvironment()

  Scenario: Run the demo code to prove it works.                                                # features/quickstart.feature:16
    Given I have installed the project                                                          # FeatureContext::iHaveInstalledTheProject()
    When I run the command to run the project's quickstart.php script                           # FeatureContext::iRunTheCommandToRunTheProjectsQuickstartPhpScript()
    Then The expected output is written to STDOUT to prove that the project code is working OK. # FeatureContext::theExpectedOutputIsWrittenToStdoutToProveThatTheProjectCodeIsWorkingOk()

2 scenarios (1 passed, 1 pending)
7 steps (5 passed, 1 pending, 1 skipped)
0m0.44s (7.66Mb)

OK good. So, my change broke nothing. Nice. Let's commit.

john-arcus added a commit that referenced this issue Apr 26, 2018
It saves having to type the PHPUnit class out each time and I can store it as an object in a property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant