2015-04-23 17:34:34 +02:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.composer_not_command import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-04-23 17:34:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def composer_not_command():
|
2015-08-17 13:44:15 +02:00
|
|
|
# that weird spacing is part of the actual command output
|
|
|
|
return (
|
|
|
|
'\n'
|
|
|
|
'\n'
|
|
|
|
' \n'
|
|
|
|
' [InvalidArgumentException] \n'
|
|
|
|
' Command "udpate" is not defined. \n'
|
|
|
|
' Did you mean this? \n'
|
|
|
|
' update \n'
|
|
|
|
' \n'
|
|
|
|
'\n'
|
|
|
|
'\n'
|
|
|
|
)
|
2015-04-23 17:34:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def composer_not_command_one_of_this():
|
2015-08-17 13:44:15 +02:00
|
|
|
# that weird spacing is part of the actual command output
|
|
|
|
return (
|
|
|
|
'\n'
|
|
|
|
'\n'
|
|
|
|
' \n'
|
|
|
|
' [InvalidArgumentException] \n'
|
|
|
|
' Command "pdate" is not defined. \n'
|
|
|
|
' Did you mean one of these? \n'
|
|
|
|
' selfupdate \n'
|
|
|
|
' self-update \n'
|
|
|
|
' update \n'
|
|
|
|
' \n'
|
|
|
|
'\n'
|
|
|
|
'\n'
|
|
|
|
)
|
2015-04-23 17:34:34 +02:00
|
|
|
|
2015-04-23 21:47:46 +02:00
|
|
|
|
2021-07-01 02:40:06 +05:30
|
|
|
@pytest.fixture
|
|
|
|
def composer_require_instead_of_install():
|
|
|
|
return 'Invalid argument package. Use "composer require package" instead to add packages to your composer.json.'
|
|
|
|
|
|
|
|
|
|
|
|
def test_match(composer_not_command, composer_not_command_one_of_this, composer_require_instead_of_install):
|
2015-04-25 02:35:26 +02:00
|
|
|
assert match(Command('composer udpate',
|
2017-08-31 17:58:56 +02:00
|
|
|
composer_not_command))
|
2015-04-25 02:35:26 +02:00
|
|
|
assert match(Command('composer pdate',
|
2017-08-31 17:58:56 +02:00
|
|
|
composer_not_command_one_of_this))
|
2021-07-01 02:40:06 +05:30
|
|
|
assert match(Command('composer install package',
|
|
|
|
composer_require_instead_of_install))
|
2017-08-31 17:58:56 +02:00
|
|
|
assert not match(Command('ls update', composer_not_command))
|
2015-04-23 17:34:34 +02:00
|
|
|
|
|
|
|
|
2021-07-01 02:40:06 +05:30
|
|
|
def test_get_new_command(composer_not_command, composer_not_command_one_of_this, composer_require_instead_of_install):
|
2016-10-06 14:51:22 -04:00
|
|
|
assert (get_new_command(Command('composer udpate',
|
2017-08-31 17:58:56 +02:00
|
|
|
composer_not_command))
|
2016-10-06 14:51:22 -04:00
|
|
|
== 'composer update')
|
2016-10-06 15:16:43 -04:00
|
|
|
assert (get_new_command(Command('composer pdate',
|
2017-08-31 17:58:56 +02:00
|
|
|
composer_not_command_one_of_this))
|
2016-10-06 15:16:43 -04:00
|
|
|
== 'composer selfupdate')
|
2021-07-01 02:40:06 +05:30
|
|
|
assert (get_new_command(Command('composer install package',
|
|
|
|
composer_require_instead_of_install))
|
|
|
|
== 'composer require package')
|