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

Setup testing environment and configure tools #419

Closed
wants to merge 74 commits into from

Conversation

antonioribeiro
Copy link
Member

@antonioribeiro antonioribeiro commented Oct 11, 2019

This is the initial test environment setup. It's not testing much yet.

It's testing, or loading

  • TwillServiceProvider boot
  • Twill install command execution
  • Database and migration setup
  • Twill module creation test, a single one for now
  • Test coverage using Coveralls

Testing tools/frameworks

We are using PHPUnit for unit tests, Testbench (also uses PHPUnit) for integration tests. In the future we shall need Laravel Dusk or Symfony Panther to execute browser (functional/acceptance) tests.

Database

We are using SQLite in :memory:.

Command line

There are some composer shortcuts:

composer test 

Which execute tests, but of course you can still call vendor/bin/phpunit, and

composer analyse

Responsible for running static analysis via PHPStan

Coverage

To look at the coverage page you just have to open its index.html file:

open tests/coverage/index.html

image

Badges

We could add some badges to the README.md if you like them:

badge
badge
badge

Code Quality

We decided, for now, to use Scrutinizer CI, the preliminary result is in my personal repository:

https://scrutinizer-ci.com/g/antonioribeiro/twill/

image

Continuous Integration

TravisCI was selected to be our CI:

https://travis-ci.org/antonioribeiro/twill

image

Code Styling

We are still discussing this, we might go towards StyleCI but it will, probably, make a lot of changes in the current source code, so I think we should take it slowly.

New base namespaces for testing

I prefer to have my tests namespaced, to avoid conflicts, so that's why we now have some more:

  • A17\Twill\Tests\Unit: unit tests
  • A17\Twill\Tests\Integration: integration tests
  • App: this namespace is needed to test the instantiation of classes created by the module command, if, you find it pointless, we can ditch it in the future.

Tools we still need to setup:

Travis must be turned on at: https://travis-ci.org/organizations/area17/repositories
Scrutinizer CI at: https://scrutinizer-ci.com/organizations/area17/repositories

@antonioribeiro antonioribeiro mentioned this pull request Oct 11, 2019
@Gummibeer
Copy link
Contributor

Gummibeer commented Oct 11, 2019

I would like to throw in https://pptr.dev/ which we have made better experience with. It's not using selenium and because of this much more stable. It's also a lot faster and because it's testing frontend the tests could be written by a frontendler via https://mochajs.org/ and https://www.chaijs.com/ without the need to know php & phpunit.

Or if you don't need browser interaction I can recommend https://github.com/spatie/phpunit-snapshot-assertions to simply compare responded HTML.

<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
Copy link
Contributor

@Gummibeer Gummibeer Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use testing to use :memory: by default. Or was this connection introduced after Laravel 5.3? :/
PS: the super low/old min Laravel version makes things very difficult.

@antonioribeiro
Copy link
Member Author

antonioribeiro commented Oct 11, 2019

@Gummibeer, you would use Puppeteer to test what exactly?

Snapshot assertions are nice if we can integrate them to a testing tool like Testbench, because for backend integration testing in Laravel apps/packages it is still the best one.

For browser testing I would try to stick to Laravel Dusk, actually Testbench-dusk, it uses Chromedriver too and is deeply integrated to the Laravel ecosystem, making it very easy to interact with fronted and check if data sent to backend is being rendered as it should, for example.

What I think we might really go non-laravel is if we start writing tests for VueJS components in isolation, it wouldn’t make sense test them using PHP, if we are not testing integration between them and the backend.

But, look, this is only a starting point. If you feel you can improve something, just shoot a proof of concept and I will gladly check and compare them, so we can all together choose the best one.

@antonioribeiro
Copy link
Member Author

antonioribeiro commented Oct 14, 2019

@Gummibeer, I'm having to manually configure database because activitylog connection must be configured separately. But I now moved them all to :memory:.

@antonioribeiro antonioribeiro force-pushed the setup-testing branch 6 times, most recently from 2ac3d99 to 18d8236 Compare October 29, 2019 22:23
@ifox
Copy link
Member

ifox commented Nov 21, 2019

All of your work is now on master after I rebased it and made it compatible with the changes coming from 1.2 and other changes for 2.0. This has been incredibly helpful and I can't thank you enough for this huge initiative for the future of Twill. Can't wait to announce 2.0 with more details about this PR!

@ifox ifox closed this Nov 21, 2019
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

Successfully merging this pull request may close these issues.

5 participants