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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

More modernization #260

Closed
wants to merge 2 commits into from

Conversation

alanpoulain
Copy link
Contributor

  • Little fixes in the source code (mainly from PHP Inspections)
  • Use latest PHPUnit
  • Declare strict typehint in test files
  • Add typehint in test files
  • Replace the PHPUnit's deprecated methods

@Baptouuuu 馃檪

@@ -39,7 +39,7 @@ $builder->buildFromIterator(
->files()
->name('*.php')
->name('*.pem*')
->exclude(['Tests', 'tests', 'phpunit'])
->exclude(['Tests', 'tests'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the PHAR needs phpunit/phpunit/src/Framework/Assert/Functions.php, autoloaded by Composer in the latest PHPUnit.

},
"config": {
"platform": {
"php": "7.1.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why locking the PHP version to 7.1.3, since all versions are tested in the CI?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This config is problematic because it tells Composer the PHP version installed is PHP 7.1.3 (see https://getcomposer.org/doc/06-config.md#platform).
It means that, in the CI, when PHP 7.4 is used, Composer is actually installing packages for PHP 7.1.3.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the initial reason of why the platform was set to php 7.1, I only specified the bugfix version so I could install psalm.

If there isn't a concrete reason to specify the php version it's better to remove it indeed. That being said I don't think it's problematic that composer install dependencies targeting 7.1, as long as the dependencies themselves are tested against 7.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's problematic, because it means you cannot test Couscous against the latest dependencies.
For instance, Symfony 5 was not tested (PHP > 7.2), and, if tested, we could have seen it was failing because of the missing return codes in the commands.

@@ -5,7 +5,6 @@
convertWarningsToExceptions="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
forceCoversAnnotation="true"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because some tests don't have the @cover annotation (and the latest PHPUnit doesn't like this).

Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

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

I've added some comments, the PR changes a lot of things in a single commit, so it's really hard to review and be confident

@@ -29,13 +29,19 @@ public function __construct(Filesystem $filesystem)
parent::__construct();
}

/**
* {@inheritdoc}
*/
Copy link
Member

Choose a reason for hiding this comment

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

Could you please revert these? (it's adding unnecessary noise)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Removing it everywhere instead then.

@@ -237,7 +237,7 @@ private function isFound(string $executablePath): bool

private function fileListToDisplay(array $files, string $sourceDirectory): string
{
$files = array_map(function (string $file) use ($sourceDirectory): string {
$files = array_map(static function (string $file) use ($sourceDirectory): string {
Copy link
Member

Choose a reason for hiding this comment

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

Same for these, they are not useful and add noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a suggestion from PHP Inspections EA:

[EA] This closure can be declared as static (better scoping; in some cases can improve performance).

Please tell me if you really want to remove them, I will do it.

@@ -93,23 +93,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($travisBranch !== 'master') {
$output->writeln('<comment>[NOT DEPLOYED] Deploying Couscous only for master branch</comment>');

return 0;
return 1;
Copy link
Member

Choose a reason for hiding this comment

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

This is a behavior change, not sure we want that. Why change that? (same for the lines below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it really a behavior change?
The return values have been added in the #259 PR.
Also it means the command has failed (EXIT_FAILURE), isn't it better? (can be useful when chaining commands in Bash for instance).

Copy link
Contributor

Choose a reason for hiding this comment

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

When I added them I used 0 as the output only contains comments and no errors (and because that's the default value set by Symfony).

As far as I understand how the CI is configured this exit code won't change the behaviour of the CI as the command is run on after_success

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, the comments look like errors, and that's why I changed the return codes, but I could be wrong.

@@ -61,11 +61,13 @@ public function getRemoteUrl(string $remote = 'origin'): string
* Check if the git repository in the provided directory has any uncommitted changes
*
* @param string $directory A directory containing a git repository
*
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a reason to do this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a CS fix to be coherent with the rest of the codebase (there is a new line before every @return everywhere else).

* @return bool True if there are changes, false otherwise
*/
public function hasUncommittedChanges(string $directory): bool
{
$changes = $this->run($directory, "git diff-index --name-only HEAD");

Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is also a CS fix to be coherent with the rest of the codebase.
It's a common CS (for instance in Symfony).

},
"config": {
"platform": {
"php": "7.1.3"
Copy link
Member

Choose a reason for hiding this comment

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

@alanpoulain
Copy link
Contributor Author

I've added some comments, the PR changes a lot of things in a single commit, so it's really hard to review and be confident

Oh sorry for that. I thought it was OK since it's mainly typehint in test files (and the tests are green).
If you really prefer I can try to separate it in different commits (src files, typehint for test files, replacement of deprecated methods).
Please tell me if you need this.

@@ -14,7 +14,7 @@
*/
class ValidateTemplateDirectory implements Step
{
const DEFAULT_TEMPLATE_DIRECTORY = 'website';
public const DEFAULT_TEMPLATE_DIRECTORY = 'website';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why make this const public when the others are private ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because this const is also used here:

$templateDirectory = $project->sourceDirectory.'/'.ValidateTemplateDirectory::DEFAULT_TEMPLATE_DIRECTORY;

@alanpoulain
Copy link
Contributor Author

Do you want me to revamp this PR? Maybe by doing small PRs instead?

@mnapoli
Copy link
Member

mnapoli commented Nov 14, 2020

Do you want me to revamp this PR? Maybe by doing small PRs instead?

Hi, yes 馃槄 I'm sorry, reviewing PRs takes a lot of time across all the repositories, and this one is huge and not top priority so I have a lot of trouble saving time for this.

Let's move forward and close this one, I don't think I'll be able to merge it. If you still want to, smaller (targeted) PRs would work better I think.

Thanks for your efforts and patience!

@mnapoli mnapoli closed this Nov 14, 2020
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.

None yet

3 participants