{"id":15685213,"url":"https://github.com/tfrommen/wceu-2018-unit-testing","last_synced_at":"2025-05-07T16:22:37.739Z","repository":{"id":72228603,"uuid":"137456547","full_name":"tfrommen/wceu-2018-unit-testing","owner":"tfrommen","description":"Code for the workshop \"An Introduction to Unit Testing (for WordPress)\" at WordCamp Europe 2018.","archived":false,"fork":false,"pushed_at":"2018-06-25T18:06:10.000Z","size":55,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T12:11:55.297Z","etag":null,"topics":["javascript","php","testing","unit-testing","wordpress"],"latest_commit_sha":null,"homepage":"https://slides.tfrommen.de/wceu-2018-unit-testing/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tfrommen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-15T07:38:57.000Z","updated_at":"2023-02-23T20:43:12.000Z","dependencies_parsed_at":"2023-02-23T08:15:16.414Z","dependency_job_id":null,"html_url":"https://github.com/tfrommen/wceu-2018-unit-testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfrommen%2Fwceu-2018-unit-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfrommen%2Fwceu-2018-unit-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfrommen%2Fwceu-2018-unit-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfrommen%2Fwceu-2018-unit-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tfrommen","download_url":"https://codeload.github.com/tfrommen/wceu-2018-unit-testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252913207,"owners_count":21824118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","php","testing","unit-testing","wordpress"],"created_at":"2024-10-03T17:24:20.446Z","updated_at":"2025-05-07T16:22:37.711Z","avatar_url":"https://github.com/tfrommen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unit Testing Workshop\n\nCode for the workshop \"An Introduction to Unit Testing (for WordPress)\" at WordCamp Europe 2018.\n\nThe **slides** are available online at [slides.tfrommen.de/wceu-2018-unit-testing](https://slides.tfrommen.de/wceu-2018-unit-testing/).\nPossible **solutions** can be found in the [`completed` branch](https://github.com/tfrommen/wceu-2018-unit-testing/tree/completed).\n\n\n## Requirements\n\nTo be able to do the exercises in this workshop, you need to meet some requirements.\n\n### PHP Requirements\n\nIn order to run the PHP tests, you need to have installed the following:\n\n* PHP 5.6 or higher (available via command line)\n* [Composer](https://getcomposer.org/)\n\n### JavaScript Requirements\n\nIn order to run the JavaScript tests, you need to have installed the following:\n\n* [Node](https://nodejs.org/) v6.0.0 or higher (available via command line)\n* [Yarn](https://yarnpkg.com/) (optional)\n\n\n## Installation\n\nHere are the steps to install and set up your environment for the workshop:\n\n1. Clone (or download) this repository to your computer.\n1. In your terminal, go to the root directory of this repository.\n1. Install the dependencies:\n    * For **PHP**, run `composer install`.\n    * For **JavaScript**, run `yarn` (or `npm i`).\n\nYou can test if everything is working by attempting to run one of the exercises as described in the next section.\n\n\n## Running the Tests\n\nEach exercise has its own test suite/file.\nTo run a specific exercise, perform the according command from the root directory of the repository, as explained below.\n\n### Running PHP Tests\n\nFor each PHP exercise, there is a dedicated _test suite_, named `exercise1` etc.\nThe generic command to run a specific test suite is as follows:\n\n```console\n./vendor/bin/phpunit --testsuite exerciseX\n```\n\nReplace the \"X\" in `exerciseX` with the exercise number.\nSo, for example, running the test suite for exercise 1 would be this:\n\n```console\n./vendor/bin/phpunit --testsuite exercise1\n```\n\n### Running JavaScript Tests\n\nFor each JavaScript exercise, there are one or more dedicated _test files_, named `exercise1/SOMETHING.test.js` etc.\nThe generic command to run a specific test suite is as follows:\n\n```console\n./node_modules/.bin/jest exerciseX\n```\n\nReplace the \"X\" in `exerciseX` with the exercise number.\nSo, for example, running the test suite for exercise 1 would be this:\n\n```console\n./node_modules/.bin/jest exercise1\n```\n\n\n## Documentation\n\nThroughout the workshop, you might want to refer to the official documentation of the tools you are using.\n\n### PHP-specific Documentation\n\n* [PHPUnit](https://phpunit.de/manual/5.7/en/index.html)\n    * [Writing Tests for PHPUnit](https://phpunit.de/manual/5.7/en/writing-tests-for-phpunit.html)\n    * [Assertions](https://phpunit.de/manual/5.7/en/appendixes.assertions.html)\n* [Brain Monkey](https://brain-wp.github.io/BrainMonkey/)\n    * [Patching with `when()`](https://brain-wp.github.io/BrainMonkey/docs/functions-when.html)\n    * [Testing with `expect()`](https://brain-wp.github.io/BrainMonkey/docs/functions-expect.html)\n    * [Testing Added Hooks](https://brain-wp.github.io/BrainMonkey/docs/wordpress-hooks-added.html)\n    * [Testing Fired Hooks](https://brain-wp.github.io/BrainMonkey/docs/wordpress-hooks-done.html)\n* [Mockery](http://docs.mockery.io/en/latest/)\n    * [Creating Test Doubles](http://docs.mockery.io/en/latest/reference/creating_test_doubles.html)\n    * [Expectation Declarations](http://docs.mockery.io/en/latest/reference/expectations.html)\n    * [Validating Types and Resources](http://docs.mockery.io/en/latest/reference/argument_validation.html#validating-types-and-resources)\n\n### JavaScript-specific Documentation\n\n* [Jest](https://facebook.github.io/jest/docs/en/getting-started.html)\n    * [Using Matchers](https://facebook.github.io/jest/docs/en/using-matchers.html)\n    * [Expect](https://facebook.github.io/jest/docs/en/expect.html)\n    * [Mock Functions](https://facebook.github.io/jest/docs/en/mock-function-api.html)\n* [Enzyme](http://airbnb.io/enzyme/)\n    * [Shallow Rendering](http://airbnb.io/enzyme/docs/api/shallow.html)\n    * [Selectors](http://airbnb.io/enzyme/docs/api/selector.html)\n* [`babel-plugin-rewire`](https://github.com/speedskater/babel-plugin-rewire/blob/master/README.md)\n    * [Named and Top-level Function Rewiring](https://github.com/speedskater/babel-plugin-rewire/blob/master/README.md#named-and-top-level-function-rewiring)\n    * [Resetting All](https://github.com/speedskater/babel-plugin-rewire/blob/master/README.md#resetting-all)\n\n\n## Have Fun!\n\nThorsten, Carl, and Giuseppe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfrommen%2Fwceu-2018-unit-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftfrommen%2Fwceu-2018-unit-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfrommen%2Fwceu-2018-unit-testing/lists"}