Commit cebfc1e2 authored by Brian Hatchet's avatar Brian Hatchet :speech_balloon:

CR updates

1 merge request!3(WIP) Chore/docs updates
......@@ -240,15 +240,109 @@ Make sure you include `@package Minds\Core\<<VideoChat>>` in `<<VideoChat>>.php`
### Executing
To run all tests:
* `bin/phpspec run`
```console
bin/phpspec run
```
To run a specific spec file (or folder), add its name:
* `bin/phpspec run Spec/Core/VideoChats/Repository.php`
```console
bin/phpspec run Spec/Core/VideoChats/Repository.php
```
To run a specific test inside of that spec file, add its starting line number:
* `bin/phpspec run Spec/Core/VideoChats/Repository.php:42`
```console
bin/phpspec run Spec/Core/VideoChats/Repository.php:42`
```
### Verbose output
Runing this command will give you deep output of the testes
```console
bin\phpspec run -vvv
```
## Writing new tests
### Creating a Spec.php file
Run this command to create a test skeleton in the appropriate place with the default classes imported.
```console
bin/phpspec run Minds/Your/Namespace/ClassYouWantToSpec
```
This will create a folder in *minds/engine/
### Mock everything
There's a lot going on under the hood in the modules, some of them have low level connectivity to the data stores. If you don't own the object, mock it. Prophesy makes it really easy
Phpspec provides easy ways to create mocks.
Inside your unit test, be sure to import the class you want to mock.
### Mocking at the test class level
Phpspec provides a *let* function that gets run before each test. If you provide a typed parameter, it will be mocked to the matching namespace.
```php
use PhpSpec\ObjectBehavior;
use Minds\Entities\Entity;
class ManagerSpec extends ObjectBehavior {
protected $entity;
let(Entity $entity) {
//Store a reference to the mock for reuse.
$this->entity = $entity
}
}
```
### Mocking at the test function level
Phpspec will provide mocks via function parameters in your test
```php
use PhpSpec\ObjectBehavior;
use Minds\Entities\Entity;
class ManagerSpec extends ObjectBehavior {
public function it_should_run_test(Entity $entity) {
}
}
```
### Setting Expectations
These mockable objects can then configured to simulate what will happen with special functions available on the mock.
ShouldBeCalled will set the expectation that mocked method should be called with a parameter.
```php
$entity->setGuid(123)->shouldBeCalled();
```
willReturn simulates the response of a mocked method
```php
$entity->setGuid(123)->willReturn($entity);
```
### Getting to the underlying object
Sometimes, php will choke on the reflection of these mocked objects (especially when constructing other objects).
```php
//This will instantiate an object and still be mockable.
$mockedObject->getList()->willReturn([]);
$service = new ServiceThatNeedsDependencies($mockedObject->getWrappedObject());
```
# Controllers
> TODO
......
......@@ -17,6 +17,8 @@ docker build -t minds/fpm:latest -f containers/php-fpm/Dockerfile .
docker build -t minds/runners:latest -f containers/php-runners/Dockerfile .
```
## Getting connected to the staging environment
## Review Apps
The review apps make use of [Helm](https://helm.sh) and [Kubernetes](https://kubernetes.io/). Our helm charts can be found [here](https://gitlab.com/minds/helm-charts) and you can inspect the review app auto deployment in our [.gitlab-ci.yml file](https://gitlab.com/minds/engine/blob/master/.gitlab-ci.yml#L52).
......@@ -51,7 +53,7 @@ helm upgrade \
### Managing settings on the Review Apps
When a pod gets deployed, it runs the installer which creates the default settings.php from the settings.example.php. However, the helm charts override those values with the template that is in our [Helm charts](https://gitlab.com/minds/helm-charts)
When a pod gets deployed, [Helm charts](https://gitlab.com/minds/helm-charts) writes in the values by parsing the [configMap.yaml](https://gitlab.com/minds/helm-charts/blob/master/minds/templates/configMap.yaml).
To have your values persist across builds, you must extend the settings.php script in the (configMap.yml) (https://gitlab.com/minds/helm-charts/blob/master/minds/templates/configMap.yaml)
......@@ -89,8 +91,7 @@ Then you must restart the pod by finding its name and deleting it.
```
kubectl get pods | grep {your.staging.site.subdomain}
kubectl delete pod/{your.staging.site.subdomain}-minds-runners-{generated.suffix.returned.by.grep}
kubectl detete pod/{your.staging.site.subdomain}-minds-php-fpm-{generated.suffix.returned.by.grep}
helm del --purge {your.staging.site.subdomain}
```
## Production
......
---
id: unit-testing
title: Unit Testing
---
# Engine unit testing
The backend runs phpspec. The tests live in minds/engine/Spec.
## Running tests
You can run all the unit tests locally by calling this command in minds/engine
```console
bin/phpspec run
```
## Running Specific tests
You can run only the tests for any class by running this command with any part of the path
```console
bin/phpspec run Spec/Core/Faq/ManagerSpec.php
```
### Verbose output
Runing this command will give you deep output of the testes
```console
bin\phpspec run -vvv
```
## Writing new tests
### Creating a Spec.php file
Run this command to create a test skeleton in the appropriate place with the default classes imported.
```console
bin/phpspec run Minds/Your/Namespace/ClassYouWantToSpec
```
This will create a folder in *minds/engine/
### Mock everything
There's a lot going on under the hood in the modules, some of them have low level connectivity to the data stores. If you don't own the object, mock it. Prophesy makes it really easy
Phpspec provides easy ways to create mocks.
Inside your unit test, be sure to import the class you want to mock.
### Mocking at the test class level
Phpspec provides a *let* function that gets run before each test. If you provide a typed parameter, it will be mocked to the matching namespace.
```php
use PhpSpec\ObjectBehavior;
use Minds\Entities\Entity;
class ManagerSpec extends ObjectBehavior {
protected $entity;
let(Entity $entity) {
//Store a reference to the mock for reuse.
$this->entity = $entity
}
}
```
### Mocking at the test function level
Phpspec will provide mocks via function parameters in your test
```php
use PhpSpec\ObjectBehavior;
use Minds\Entities\Entity;
class ManagerSpec extends ObjectBehavior {
public function it_should_run_test(Entity $entity) {
}
}
```
### Setting Expectations
These mockable objects can then configured to simulate what will happen with special functions available on the mock.
ShouldBeCalled will set the expectation that mocked method should be called with a parameter.
```php
$entity->setGuid(123)->shouldBeCalled();
```
willReturn simulates the response of a mocked method
```php
$entity->setGuid(123)->willReturn($entity);
```
### Getting to the underlying object
Sometimes, php will choke on the reflection of these mocked objects (especially when constructing other objects).
```php
//This will instantiate an object and still be mockable.
$mockedObject->getList()->willReturn([]);
$service = new ServiceThatNeedsDependencies($mockedObject->getWrappedObject());
```
......@@ -38,9 +38,6 @@
},
"guides/mobile": {
"title": "Mobile"
},
"guides/unit-testing": {
"title": "Unit Testing"
}
},
"links": {
......
......@@ -11,8 +11,7 @@
"guides/mobile",
"guides/kubenetes",
"guides/deployment",
"guides/git",
"guides/unit-testing"
"guides/git"
],
"Contributing": [
"contributing/contributing",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment