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

test-related questions, understand whether you need to change the test in the testMcryptGenericMode #21

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jhonatasfender
Copy link

Well I noticed that in the tests has a "Risky", and I went to look at the code:

    /**
     * @dataProvider mcryptBlockModuleNameProvider
     */
    public function testMcryptGenericMode($modeName, $validMode)
    {
        if (!$validMode) {
            return;
        }
        $key = str_repeat('a', 16);
        $iv = str_repeat('b', 16);
        $plaintext = str_repeat('c', 16);
        $mcrypt = mcrypt_encrypt('rijndael-128', $key, $plaintext, $modeName, $iv);
        $compat = phpseclib_mcrypt_encrypt('rijndael-128', $key, $plaintext, $modeName, $iv);
        $this->assertEquals(bin2hex($mcrypt), bin2hex($compat));
    }

And you wanted to know if it's for you this way, or do you accept that you make changes to this method?

I ran the tests on my machine, and this was the displayed log of script execution:

$ ./vendor/bin/phpunit
PHPUnit 6.5.10 by Sebastian Bergmann and contributors.

.....................S.S.S.....................................  63 / 132 ( 47%)
.............SSS.S.SSS.SSS.SSS.S.S.S.S.S.S.S.S.S.S.S.S.S...SS.. 126 / 132 ( 95%)
.....R                                                          132 / 132 (100%)

Time: 15.28 minutes, Memory: 6.00MB

There was 1 risky test:

1) MCryptCompatTest::testMcryptGenericMode with data set #6 ('invalid-mode', false)
This test did not perform any assertions

OK, but incomplete, skipped, or risky tests!
Tests: 132, Assertions: 186, Skipped: 31, Risky: 1.

jonatas.rodrigues added 7 commits August 6, 2018 19:16
…vider method, which loads the listing without the invalid-module
…vider method, which loads the listing without the invalid-module
…vider method, which loads the listing without the invalid-module
…vider method, which loads the listing without the invalid-module
…vider method, which loads the listing without the invalid-module
…vider method, which loads the listing without the invalid-module
@terrafrost
Copy link
Member

First, you should squash your commits into a single commit.

Second, you shouldn't include a composer.lock file. That's more intended for projects - not libraries. https://blog.martinhujer.cz/17-tips-for-using-composer-efficiently/ elaborates.

I'll make a few other comments in line.

@terrafrost
Copy link
Member

Well, actually, I'm not sure in-line comments are necessary.

I'm not sure your README.md changes make a lot of sense. You say, in a newly added "How to Contribute" section, simply "composer install". That's doesn't really tell me how to contribute. And the new "Tests" section... idk it seems a bit redundant to me. ./vendor/bin/phpunit is pretty standard...

You did identify a few areas that could benefit from coding standards cleanup. eg. changing case'tripledes': to case 'tripledes': is an obvious improvement. But some of the other changes are more subjective in nature. eg. changing this:

return $mode[0] == 'N' ?
    'n' . substr($mode, 1) :
    $mode;

...to this:

return $mode[0] == 'N' ? 'n' . substr($mode, 1) : $mode;

And for the unit tests... you changed the data provider for testMcryptGenericMode to a new method - mcryptBlockModuleNameWithoutInvalidModuleProvider. If we're gonna have a new method, however, then why pass two parameters? Why not just pass one? In this new method every mode is valid so there's no need to pass the valid status to testMcryptGenericMode...

@jhonatasfender
Copy link
Author

Thank you very much for the comments, I will make the necessary changes, and remove those redundant ones.

In the test question, I created a new method to solve a problem that I was presenting as a risk, and then I detected that I had an invalid-mode option with a false value, and then I immediately followed a validation and returned, where I decided to create a new provider with different values.

Thank you very much in advance.

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.

2 participants