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

Feature test inflections #2187

Open
wants to merge 32 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
259adb9
unit tests: making test case setUp() functions return void
namespacebrian Aug 31, 2021
4df7349
unit tests: making test case setUp() functions return void
namespacebrian Aug 31, 2021
ec99ac6
unit tests: make more methods compatible with parent class
namespacebrian Aug 31, 2021
7a3d0e2
Fix unit_tests/Hooks/RoleValidatorTest.php
namespacebrian Sep 1, 2021
af85baf
composer.json adjustments for working on unit tests
namespacebrian Sep 1, 2021
2a36ea3
TerminusModel is unavailable in PaymentMethod...
namespacebrian Sep 1, 2021
c3df207
Fixed TerminusModel class unavailable error
namespacebrian Sep 1, 2021
6c554e4
composer.lock w/php7.3 and unit test output text file
namespacebrian Sep 1, 2021
47d25c8
WIP: fix unit tests
greg-1-anderson Sep 2, 2021
0c791a9
Adjust some setExpectedException()s
namespacebrian Sep 2, 2021
a50341e
Fix config for phpunit 9
greg-1-anderson Sep 2, 2021
72c236d
More inflection work
greg-1-anderson Sep 2, 2021
cf119ba
Merge branch 'feature/3.x-unit-tests' of github.com:pantheon-systems/…
greg-1-anderson Sep 2, 2021
778fdd3
Fix more setExpectedException()s
namespacebrian Sep 2, 2021
7a6c4b3
Fix setExpectedException()s - round 3
namespacebrian Sep 2, 2021
fa92b8e
lol stahp the CI for now
namespacebrian Sep 2, 2021
6d2c573
Still more CI needs stopped
namespacebrian Sep 2, 2021
8898ec7
Just move ci.yml...
namespacebrian Sep 2, 2021
c97b255
Can uncomment the ci.yml stuff now that it's moved
namespacebrian Sep 2, 2021
f8ac142
Fix setExpectedException()s - round 4
namespacebrian Sep 2, 2021
7eb760e
Use inflection with d9ify
greg-1-anderson Sep 2, 2021
1f2ea5b
Merge branch 'feature/3.x-unit-tests' of github.com:pantheon-systems/…
greg-1-anderson Sep 2, 2021
f26d180
Merge branch '3.x' into feature/3.x-unit-tests
greg-1-anderson Sep 3, 2021
21c2834
More inflectors
greg-1-anderson Sep 3, 2021
d82600e
Even more inflection
greg-1-anderson Sep 3, 2021
3794858
Move ci back
greg-1-anderson Sep 3, 2021
6978331
Restore ci.yml from 3.x branch
greg-1-anderson Sep 3, 2021
77578d6
getMock -> createMock
greg-1-anderson Sep 3, 2021
f792001
Add instructions on running the functional tests locally
greg-1-anderson Sep 3, 2021
62bb689
More test fixes
greg-1-anderson Sep 3, 2021
97a8c48
Mark test skipped on RequestTests that are no longer mockable.
greg-1-anderson Sep 7, 2021
1b263ca
README.md updates: brew install & running tests
namespacebrian Sep 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ These packages will install when you install Terminus.

`*** TBD ***`

## Testing

To run the functional tests:

1. If you need the basics (php, git, direnv, etc): `brew bundle install`
2. For code coverage: `pecl install pcov`
Copy link
Contributor

Choose a reason for hiding this comment

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

for what it's worth, this was required for them to run, at least when I first got them to run and I can't see why it would have changed.

3. Prepare a new test site, e.g. make a new multidev in ci-terminus-composer
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests currently have the environment hard-coded in most cases, e.g. LocalCommandsTest.php line 64, and line 81 as well. In the tests/Functional directory, when I run ack 'live' | grep 'live' | wc -l gives returns 29, and skimming the results, those matches look like the environment name in every case.

So even if you create a multidev, most of the time it's going to run against the hard-coded environment.

Obviously this needs to be fixed.

4. Copy .env.dist to .env and make an .envrc to include it with `dotenv`, or copy .env.dist to .envrc and add `export` at the head of each line. Customize values as needed. Use `direnv allow` to enable automatic loading of environment variables needed for tests.
5. Run `composer test:short` to run the short functional tests, or `composer test:long` to run everything.
Copy link
Contributor

Choose a reason for hiding this comment

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

composer test:long runs only the long-running tests, i.e. it won't run the short tests. This was so we could run all tests by running both commands separately. Until I changed test:functional to run both short and long tests, late last week, it ran all the tests, including the un-implemented ones which still fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

pushed update for this.



| Command | Description | ⚖️ |
| ------------------------- | ------------------------------------------------------------ | -- |
Expand Down
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=7.4",
"php": ">=7.3",
"ext-json": "*",
"composer/composer": "^2",
"composer/semver": "^3",
Expand Down Expand Up @@ -62,6 +62,7 @@
"autoload-dev": {
"psr-4": {
"Pantheon\\Terminus\\Tests\\Functional\\": "tests/Functional/",
"Pantheon\\Terminus\\UnitTests\\": "tests/unit_tests/",
"Pantheon\\Terminus\\FeatureTests\\": "tests/features/bootstrap/"
},
"classmap": [
Expand All @@ -74,6 +75,12 @@
"scripts": {
"build": "@phar:build",
"test": "@test:functional",
"phar:install-tools": [
"gem install mime-types -v 2.6.2",
"curl -LSs https://box-project.github.io/box2/installer.php | php",
"mkdir -p tools",
"mv -f box.phar tools/box"
],
Copy link
Contributor

Choose a reason for hiding this comment

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

I put this stuff here while trying to get the unit tests to run.. but I don't know that it's actually needed for them

"phar:build": [
"rm -Rf ./t3",
"vendor/bin/phar-composer.phar build .",
Expand Down Expand Up @@ -135,6 +142,9 @@
"cs": [
"vendor/bin/phpcs --standard=tests/config/linting_ruleset.xml bin/t3 src tests/Functional"
],
"phpunit": [
"SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit.xml.dist --debug"
],
"docs": [
"vendor/bin/robo doc ./README.md",
"git add README.md"
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Collections/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pantheon\Terminus\Collections;

use Pantheon\Terminus\Models\TerminusModel;
use Pantheon\Terminus\Exceptions\TerminusException;
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Models\PaymentMethod;
Expand Down Expand Up @@ -30,7 +31,7 @@ class PaymentMethods extends UserOwnedCollection
* @throws TerminusException When there is more than one matching payment method
* @throws TerminusNotFoundException When there are no matching payment methods
*/
public function get($id)
public function get($id): TerminusModel
{
$payment_methods = $this->all();
if (isset($payment_methods[$id])) {
Expand Down
12 changes: 5 additions & 7 deletions src/Collections/SavedTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ public function add($model_data, array $options = [])
*/
public function create($token_string)
{
$token_nickname = "token-" . \uniqid();
$this->getContainer()->add($token_nickname, SavedToken::class)
->addArguments([
(object)['token' => $token_string],
['collection' => $this]
]);
$token = $this->getContainer()->get($token_nickname);
$token = new SavedToken(
(object)['token' => $token_string],
['collection' => $this]
);
$this->getContainer()->inflect($token);
$token->setDataStore($this->getDataStore());
$user = $token->logIn();
$user->fetch();
Expand Down
14 changes: 5 additions & 9 deletions src/Collections/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,11 @@ public function get($id): ?TerminusModel
$uuid = $this->findUUIDByNameOrUUID($id);
$site = $this->models[$uuid] ?? null;
if (!$site instanceof Site) {
$nickname = 'site-' . $uuid;
$this->getContainer()->add($nickname, $this->collected_class)
->addArguments(
[
(object)['id' => $uuid],
['id' => $uuid, 'collection' => $this]
]
);
$site = $this->getContainer()->get($nickname);
$site = new $this->collected_class(
(object)['id' => $uuid],
['id' => $uuid, 'collection' => $this]
);
$this->getContainer()->inflect($site);
$site->fetch();
if (!$site->valid()) {
throw new TerminusException("Site is not valid!");
Expand Down
11 changes: 5 additions & 6 deletions src/Collections/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ public function create($tag)
"organizations/{$this->org_site_membership->getOrganization()->id}/tags",
['method' => 'put', 'form_params' => $params,]
);
$this->getContainer()->add($this->collected_class)
->addArguments([
(object)['id' => $tag],
['collection' => $this],
]);
$this->models[$tag] = $this->getContainer()->get($this->collected_class);
$this->models[$tag] = new $this->collected_class(
(object)['id' => $tag],
['collection' => $this]
);
$this->getContainer()->inflect($this->models[$tag]);
return $this->models[$tag];
}

Expand Down
7 changes: 2 additions & 5 deletions src/Collections/TerminusCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ public function add($model_data, array $options = [])
['id' => $model_data->id, 'collection' => $this],
$options
);
$nickname = \uniqid($model_data->id);

$this->getContainer()->add($nickname, $this->collected_class)
->addArguments([$model_data, $options]);
$model = $this->getContainer()->get($nickname);
$model = new $this->collected_class($model_data, $options);
$this->getContainer()->inflect($model);
$this->models[$model_data->id] = $model;
return $model;
}
Expand Down
21 changes: 9 additions & 12 deletions src/Collections/Workflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function ($workflow) {
*/
public function create($type, array $options = [])
{

$params = $options['params'] ?? [];
$results = $this->request()->request(
$this->getUrl(),
Expand All @@ -109,17 +108,15 @@ public function create($type, array $options = [])
['error' => $results->getStatusCodeReason()]
);
}
$nickname = \uniqid(__CLASS__ . "-");
$this->getContainer()->add($nickname, $this->collected_class)
->addArguments([
$results->getData(),
[
'id' => $results->getData()->id,
'collection' => $this,
'owner' => $this->owner
]
]);
$model = $this->getContainer()->get($nickname);
$model = new $this->collected_class(
$results->getData(),
[
'id' => $results->getData()->id,
'collection' => $this,
'owner' => $this->owner
]
);
$this->getContainer()->inflect($model);
$this->add($model);
return $model;
}
Expand Down
21 changes: 9 additions & 12 deletions src/Commands/AliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,19 @@ protected function getAliasEmitters($options)
$emitters = [];

if ($this->emitterTypeMatches($emitterType, 'print', false)) {
$print_nickname = \uniqid(__METHOD__);
$this->getContainer()->add($print_nickname, PrintingEmitter::class)
->addArguments([$this->output()]);
$emitters[] = $this->getContainer()->get($print_nickname);
$printingEmitter = new PrintingEmitter($this->output());
$this->getContainer()->inflect($printingEmitter);
$emitters[] = $printingEmitter;
}
if ($this->emitterTypeMatches($emitterType, 'php')) {
$php_nickname = \uniqid(__METHOD__);
$this->getContainer()->add($php_nickname, AliasesDrushRcEmitter::class)
->addArguments([$location, $base_dir]);
$emitters[] = $this->getContainer()->get($php_nickname);
$drushRcEmitter = new AliasesDrushRcEmitter($location, $base_dir);
$this->getContainer()->inflect($drushRcEmitter);
$emitters[] = $drushRcEmitter;
}
if ($this->emitterTypeMatches($emitterType, 'yml')) {
$yml_nickname = \uniqid(__METHOD__);
$this->getContainer()->add($yml_nickname, DrushSitesYmlEmitter::class)
->addArguments([$base_dir, $home, $target_name]);
$emitters[] = $this->getContainer()->get($yml_nickname);
$sitesYmlEmitter = new DrushSitesYmlEmitter($base_dir, $home, $target_name);
$this->getContainer()->inflect($sitesYmlEmitter);
$emitters[] = $sitesYmlEmitter;
}

return $emitters;
Expand Down
29 changes: 13 additions & 16 deletions src/Commands/D9ify/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ public function process($sourceSite, $destinationSite = null, $options = [])
$sourceSiteObject = $this->getSite($sourceSite);
}
if (isset($sourceSiteObject) && $sourceSiteObject instanceof Site) {
$this->getContainer()->add("sourceDir", Directory::class)
->addArgument(['site' => $sourceSiteObject]);
$this->sourceDirectory = $this->getContainer()->get("sourceDir");
$this->sourceDirectory = new Directory(['site' => $sourceSiteObject]);
$this->getContainer()->inflect($this->sourceDirectory);
}

// Create destination Site if not exists or value is null.
Expand Down Expand Up @@ -115,8 +114,8 @@ public function process($sourceSite, $destinationSite = null, $options = [])
}

if (!isset($destinationSiteObject) || !$destinationSiteObject instanceof Site) {
$this->getContainer()->add(CreateCommand::class);
$createCommand = $this->getContainer()->get(CreateCommand::class);
$createCommand = new CreateCommand();
$this->getContainer()->inflect($createCommand);
$createCommand->create(
$destinationSite,
$destinationSite,
Expand All @@ -125,14 +124,12 @@ public function process($sourceSite, $destinationSite = null, $options = [])
);
$destinationSiteInfoCommand = $this->getContainer()->get(InfoCommand::class);
$destinationSiteInfo = $destinationSiteInfoCommand->info($destinationSite)->getArrayCopy();
$this->getContainer()->add('destinationSiteModel', Site::class)
->addArgument($destinationSiteInfo);
$destinationSiteObject = $this->getContainer()->get('destinationSiteModel');
$destinationSiteObject = new Site($destinationSiteInfo);
$this->getContainer()->inflect($destinationSiteObject);
}
if (isset($destinationSiteObject) || $destinationSiteObject instanceof Site) {
$this->getContainer()->add('destinationDir', Directory::class)
->addArgument(['site' => $destinationSiteObject ]);
$this->destinationDirectory = $this->getContainer()->get('destinationDir');
if (isset($destinationSiteObject) && $destinationSiteObject instanceof Site) {
$this->destinationDirectory = new Directory(['site' => $destinationSiteObject ]);
$this->getContainer()->inflect($this->destinationDirectory);
}

if (!isset($this->sourceDirectory) || !isset($this->destinationDirectory)) {
Expand Down Expand Up @@ -643,8 +640,8 @@ protected function copyConfigFiles()
*/
protected function downloadDatabase()
{
$this->getContainer()->add(GetLiveDBCommand::class);
$downloadDbCommand = $this->getContainer()->get(GetLiveDBCommand::class);
$downloadDbCommand = new GetLiveDBCommand();
$this->getContainer()->inflect($downloadDbCommand);
$downloadDbCommand->downloadLiveDbBackup($this->getSourceDirectory()->getSource());
}

Expand All @@ -661,8 +658,8 @@ protected function downloadDatabase()
*/
protected function downloadSourceSiteFilesDirectory()
{
$this->getContainer()->add(GetLiveFilesCommand::class);
$downloadFilesCommand = $this->getContainer()->get(GetLiveFilesCommand::class);
$downloadFilesCommand = new GetLiveFilesCommand();
$this->getContainer()->inflect($downloadFilesCommand);
$downloadFilesCommand->downloadLiveFilesBackup($this->getSourceDirectory()->getSource());
}
}
6 changes: 2 additions & 4 deletions src/Commands/WorkflowProcessingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ trait WorkflowProcessingTrait
public function processWorkflow(Workflow $workflow): ?Workflow
{
if ($this->input()->isInteractive()) {
$nickname = \uniqid(__METHOD__ . "-");
$this->getContainer()->add($nickname, WorkflowProgressBar::class)
->addArguments([$this->output(), $workflow]);
$progressBar = $this->getContainer()->get($nickname);
$progressBar = new WorkflowProgressBar($this->output(), $workflow);
$this->getContainer()->inflect($progressBar);
return $progressBar->cycle();
}
$retry_interval = $this->getConfig()->get('http_retry_delay_ms', 100);
Expand Down
7 changes: 2 additions & 5 deletions src/Friends/OrganizationJoinTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ public function getReferences()
public function getOrganization()
{
if (empty($this->organization)) {
$nickname = \uniqid(__FUNCTION__ . "-");
$this->getContainer()
->add($nickname, Organization::class)
->addArgument($this->get('organization'));
$organization = $this->getContainer()->get($nickname);
$organization = new Organization($this->get('organization'));
$this->getContainer()->inflect($organization);
$organization->memberships = [$this];
$this->setOrganization($organization);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Friends/ProfileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ trait ProfileTrait
public function getProfile()
{
if (empty($this->profile)) {
$nickname = \uniqid(__FUNCTION__ . "-");
$this->getContainer()->add($nickname, Profile::class)
->addArgument([$this->get('profile')]);
$profile = $this->getContainer()->get($nickname);
$profile = new Profile([$this->get('profile')]);
$this->getContainer()->inflect($profile);
$this->setProfile($profile);
}
return $this->profile;
Expand Down
7 changes: 1 addition & 6 deletions src/Friends/SiteJoinTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ public function getReferences()
public function getSite()
{
if (empty($this->site)) {
$nickname = \uniqid(__FUNCTION__ . "-");
$this->getContainer()
->add($nickname, Site::class)
->addArgument($this->get('site'));
$site = $this->getContainer()
->get($nickname);
$site = new Site($this->get('site'));
$site->memberships = [$this];
$this->setSite($site);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Friends/UserJoinTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ public function getReferences()
public function getUser()
{
if (empty($this->user)) {
$nickname = \uniqid(__FUNCTION__ . '-');
$this->getContainer()
->add($nickname, User::class)
->addArgument($this->get('user'));
$user = $this->getContainer()->get($nickname);
$user = new User($this->get('user'));
$this->getContainer()->inflect($user);
$user->memberships = [$this];
$this->setUser($user);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ public function getFinder()
public function getProgressBar(Process $process)
{
$process->start();
$nickname = \uniqid(__METHOD__ . "-");
$this->getContainer()->add($nickname, ProcessProgressBar::class)
->addArguments([$this->output(), $process]);
$progressBar = new ProcessProgressBar($this->output(), $process);
$this->getContainer()->inflect($progressBar);
return $this->getContainer()->get($nickname);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/Site/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public function ensureLocalCopyOfRepo(bool $create = false)
throw new \Exception("Site does not exist and cannot be created.");
}
}
$this->getContainer()->add(CloneCommand::class);
$cloneCommand = $this->getContainer()->get(CloneCommand::class);
$cloneCommand = new CloneCommand();
$this->getContainer()->inflect($cloneCommand);
$clonePath = $cloneCommand->clone($this->getSource());
$this->logger->info("Clone Path:" . $clonePath);
$this->setClonePath($clonePath);
Expand Down
Loading