diff --git a/src/Commands/Base/BaseCommand.php b/src/Commands/Base/BaseCommand.php index a739d61..ceeead6 100644 --- a/src/Commands/Base/BaseCommand.php +++ b/src/Commands/Base/BaseCommand.php @@ -10,13 +10,15 @@ **/ namespace Talevskiigor\ComposerBump\Commands\Base; - use Illuminate\Console\Command; - use Talevskiigor\ComposerBump\Helpers\Bumper; use Talevskiigor\ComposerBump\Helpers\FileHelper; - +/** + * Class BaseCommand + * + * @package Talevskiigor\ComposerBump\Commands\Base + */ class BaseCommand extends Command { /** @@ -33,7 +35,6 @@ class BaseCommand extends Command */ protected $description = ''; - /** * Create a new command instance. */ @@ -45,7 +46,6 @@ public function __construct() } - /** * Execute the console command. * @return mixed @@ -53,13 +53,6 @@ public function __construct() */ public function handle() { - - throw new \Exception("You need to implement your own handle() method.", 1); - - } - - - - - + throw new \Exception("You need to implement your own handle() method.", 1); + } } diff --git a/src/Commands/BumpCommand.php b/src/Commands/BumpCommand.php index 623c575..47a5440 100644 --- a/src/Commands/BumpCommand.php +++ b/src/Commands/BumpCommand.php @@ -4,6 +4,11 @@ use Talevskiigor\ComposerBump\Commands\Base\BaseCommand; +/** + * Class BumpCommand + * + * @package Talevskiigor\ComposerBump\Commands + */ class BumpCommand extends BaseCommand { /** @@ -20,10 +25,6 @@ class BumpCommand extends BaseCommand */ protected $description = 'Bump version (This is alias of bump:patch)'; - - - - /** * Execute the console command. * @@ -31,14 +32,9 @@ class BumpCommand extends BaseCommand */ public function handle() { - - $oldVersion = $this->fileHelper->getVersion(); - - $newVersion = $this->bumper->bump($oldVersion)->get(); - - $this->fileHelper->setVersion($newVersion)->save(); - - $this->info('Bump from: '. $oldVersion.' to ' . $newVersion); - } - + $oldVersion = $this->fileHelper->getVersion(); + $newVersion = $this->bumper->bump($oldVersion)->get(); + $this->fileHelper->setVersion($newVersion)->save(); + $this->info('Bump from: ' . $oldVersion . ' to ' . $newVersion); + } } diff --git a/src/Commands/BumpMajorCommand.php b/src/Commands/BumpMajorCommand.php index 3209ed4..d40ff4f 100644 --- a/src/Commands/BumpMajorCommand.php +++ b/src/Commands/BumpMajorCommand.php @@ -1,10 +1,14 @@ verison 1.0.0)'; - - - - + protected $description = 'Bump MAJOR version (MAJOR.minor.patch => version 1.0.0)'; /** * Execute the console command. @@ -32,13 +32,9 @@ class BumpMajorCommand extends BaseCommand */ public function handle() { - $oldVersion = $this->fileHelper->getVersion(); - $newVersion = $this->bumper->bumpMajor($oldVersion)->get(); - $this->fileHelper->setVersion($newVersion)->save(); - $this->info('Bump from: '. $oldVersion.' to ' . $newVersion); } diff --git a/src/Commands/BumpMinorCommand.php b/src/Commands/BumpMinorCommand.php index 2a4c5b5..d9ceba6 100644 --- a/src/Commands/BumpMinorCommand.php +++ b/src/Commands/BumpMinorCommand.php @@ -4,6 +4,11 @@ use Talevskiigor\ComposerBump\Commands\Base\BaseCommand; +/** + * Class BumpMinorCommand + * + * @package Talevskiigor\ComposerBump\Commands + */ class BumpMinorCommand extends BaseCommand { /** @@ -18,11 +23,7 @@ class BumpMinorCommand extends BaseCommand * * @var string */ - protected $description = 'Bump MINOR version (major.MINOR.patch => verison 0.1.0)'; - - - - + protected $description = 'Bump MINOR version (major.MINOR.patch => version 0.1.0)'; /** * Execute the console command. @@ -31,14 +32,10 @@ class BumpMinorCommand extends BaseCommand */ public function handle() { - - $oldVersion = $this->fileHelper->getVersion(); - - $newVersion = $this->bumper->bumpMinor($oldVersion)->get(); - - $this->fileHelper->setVersion($newVersion)->save(); - - $this->info('Bump from: '. $oldVersion.' to ' . $newVersion); - } + $oldVersion = $this->fileHelper->getVersion(); + $newVersion = $this->bumper->bumpMinor($oldVersion)->get(); + $this->fileHelper->setVersion($newVersion)->save(); + $this->info('Bump from: ' . $oldVersion . ' to ' . $newVersion); + } } diff --git a/src/Commands/BumpPatchCommand.php b/src/Commands/BumpPatchCommand.php index 78bd6ff..e681eee 100644 --- a/src/Commands/BumpPatchCommand.php +++ b/src/Commands/BumpPatchCommand.php @@ -4,6 +4,11 @@ use Talevskiigor\ComposerBump\Commands\Base\BaseCommand; +/** + * Class BumpPatchCommand + * + * @package Talevskiigor\ComposerBump\Commands + */ class BumpPatchCommand extends BaseCommand { /** @@ -20,10 +25,6 @@ class BumpPatchCommand extends BaseCommand */ protected $description = 'Increments PATCH version (major.minor.PATCH => verison 0.0.1)'; - - - - /** * Execute the console command. * @@ -31,15 +32,9 @@ class BumpPatchCommand extends BaseCommand */ public function handle() { - - $oldVersion = $this->fileHelper->getVersion(); - - $newVersion = $this->bumper->bumpPatch($oldVersion)->get(); - - $this->fileHelper->setVersion($newVersion)->save(); - - $this->info('Bump from: '. $oldVersion.' to ' . $newVersion); - } - - + $oldVersion = $this->fileHelper->getVersion(); + $newVersion = $this->bumper->bumpPatch($oldVersion)->get(); + $this->fileHelper->setVersion($newVersion)->save(); + $this->info('Bump from: ' . $oldVersion . ' to ' . $newVersion); + } } diff --git a/src/Commands/UndoBumpCommand.php b/src/Commands/UndoBumpCommand.php index 1019f39..b9bcefa 100644 --- a/src/Commands/UndoBumpCommand.php +++ b/src/Commands/UndoBumpCommand.php @@ -4,6 +4,11 @@ use Talevskiigor\ComposerBump\Commands\Base\BaseCommand; +/** + * Class UndoBumpCommand + * + * @package Talevskiigor\ComposerBump\Commands + */ class UndoBumpCommand extends BaseCommand { /** @@ -20,29 +25,21 @@ class UndoBumpCommand extends BaseCommand */ protected $description = 'Restore last changes in the compose.json'; - - - - /** * Execute the console command. * * @return mixed + * @throws \Exception */ public function handle() { - $this->error(str_repeat('!!! WARNING !!!',3)); $this->error(' This will replace content of: composer.json file with content from file: composer.json-backup !!!'); if ($this->confirm('Are you suere? [y|N]')) { $this->fileHelper->restoreBackupFile(); $this->info('Restored file: composer.json-backup into file: composer.json'); - }else { + } else { $this->info('Action was canceled.'); } - - - } - - + } } diff --git a/src/ComposerBump.php b/src/ComposerBump.php index ca9b841..eb25a87 100644 --- a/src/ComposerBump.php +++ b/src/ComposerBump.php @@ -1,18 +1,40 @@ -fileHelper = new \Talevskiigor\ComposerBump\Helpers\FileHelper(); - } +/** + * Class ComposerBump + * + * @package Talevskiigor\ComposerBump + */ +class ComposerBump +{ + /** + * ComposerBump constructor. + */ + public function __construct() + { + $this->fileHelper = new \Talevskiigor\ComposerBump\Helpers\FileHelper(); + } - public function version(){ - return $this->getVersion(); - } + /** + * Get Version (alias) + * + * @return |null + */ + public function version() + { + return $this->getVersion(); + } - public function getVersion(){ - return $this->fileHelper->getVersion(); - } + /** + * Get Version + * + * @return string|null + */ + public function getVersion() + { + return $this->fileHelper->getVersion(); + } -} \ No newline at end of file +} diff --git a/src/ComposerBumpServiceProvider.php b/src/ComposerBumpServiceProvider.php index 6c39642..3d0eb45 100644 --- a/src/ComposerBumpServiceProvider.php +++ b/src/ComposerBumpServiceProvider.php @@ -1,12 +1,16 @@ mergeConfigFrom( __DIR__ . '/config.php', 'ComposerBump' ); @@ -32,21 +35,14 @@ public function boot() */ public function register() { - $this->app->bind('ComposerBump', \Talevskiigor\ComposerBump\ComposerBump::class); - $this->registerBumpGenerator(); - $this->registerBumpPatchGenerator(); - $this->registerBumpMinorGenerator(); - $this->registerBumpMajorGenerator(); - $this->registerUndoBump(); } - private function registerBumpGenerator() { $this->app->singleton('bump.bump', function ($app) { @@ -91,4 +87,4 @@ private function registerUndoBump() $this->commands('bump.bump.undo'); } -} \ No newline at end of file +} diff --git a/src/Facades/ComposerBump.php b/src/Facades/ComposerBump.php index 29329fe..459e0a2 100644 --- a/src/Facades/ComposerBump.php +++ b/src/Facades/ComposerBump.php @@ -2,12 +2,20 @@ namespace Talevskiigor\ComposerBump\Facades; +/** + * Class ComposerBump + * + * @package Talevskiigor\ComposerBump\Facades + */ class ComposerBump extends \Illuminate\Support\Facades\Facade { - /** + /** * Get the registered name of the component. * * @return string */ - protected static function getFacadeAccessor() { return 'ComposerBump'; } + protected static function getFacadeAccessor() + { + return 'ComposerBump'; + } } diff --git a/tests/BumperTest.php b/tests/BumperTest.php index 68ba758..a589546 100644 --- a/tests/BumperTest.php +++ b/tests/BumperTest.php @@ -4,128 +4,132 @@ use PHPUnit_Framework_TestCase; use Talevskiigor\ComposerBump\Helpers\Bumper; +/** + * Class BumperTest + * + * @package Tests + */ class BumperTest extends PHPUnit_Framework_TestCase { - - function __construct() - { - } + /** @test */ + public function it_will_increment_bump_version_as_alias_of_bumpPatch() + { + $bumper = new Bumper; + $version = $bumper->bumpPatch('1.2.3')->get(); - /** @test */ - public function it_will_increment_bump_version_as_alias_of_bumpPatch(){ - $bumper = new Bumper; + $this->assertEquals('1.2.4', $version); + } - $version = $bumper->bumpPatch('1.2.3')->get(); + /** @test */ + public function it_will_increment_patch_version() + { + $bumper = new Bumper; - $this->assertEquals('1.2.4',$version); - } + $version = $bumper->bumpPatch('1.2.3')->get(); - /** @test */ - public function it_will_increment_patch_version(){ - $bumper = new Bumper; + $this->assertEquals('1.2.4', $version); + } - $version = $bumper->bumpPatch('1.2.3')->get(); + /** @test */ + public function it_will_increment_minor_version() + { + $bumper = new Bumper; - $this->assertEquals('1.2.4',$version); - } + $version = $bumper->bumpMinor('1.2.3')->get(); - /** @test */ - public function it_will_increment_minor_version(){ - $bumper = new Bumper; + $this->assertEquals('1.3.0', $version); + } - $version = $bumper->bumpMinor('1.2.3')->get(); + /** @test */ + public function it_will_increment_major_version() + { + $bumper = new Bumper; - $this->assertEquals('1.3.0',$version); - } + $version = $bumper->bumpMajor('1.2.3')->get(); - /** @test */ - public function it_will_increment_major_version(){ - $bumper = new Bumper; + $this->assertEquals('2.0.0', $version); + } - $version = $bumper->bumpMajor('1.2.3')->get(); - - $this->assertEquals('2.0.0',$version); - } - - /** - * @test - * @expectedException Exception + /** + * @test + * @expectedException Exception **/ - public function it_will_throw_exception_on_invalid_number_of_args_for_patch(){ - $bumper = new Bumper; - - $bumper->bumpPatch('1.2.3.4.5')->get(); - } - /** - * @test - * @expectedException Exception - **/ - public function it_will_throw_exception_on_invalid_strings_in_version_for_patch(){ - $bumper = new Bumper; - - $bumper->bumpPatch('a.b.c')->get(); - } + public function it_will_throw_exception_on_invalid_number_of_args_for_patch() + { + $bumper = new Bumper; - /** @test */ - public function it_will_return_inital_bump_value_where_version_is_null_or_empty_or_false(){ + $bumper->bumpPatch('1.2.3.4.5')->get(); + } - $bumper = new Bumper; - - $versionNull = $bumper->bump(null)->get(); - $this->assertEquals('0.0.1',$versionNull); - - $versionEmptyString = $bumper->bump(null)->get(); - $this->assertEquals('0.0.1',$versionEmptyString); + /** + * @test + * @expectedException Exception + **/ + public function it_will_throw_exception_on_invalid_strings_in_version_for_patch() + { + $bumper = new Bumper; - $versionFalse = $bumper->bump(false)->get(); - $this->assertEquals('0.0.1',$versionFalse); - } + $bumper->bumpPatch('a.b.c')->get(); + } - /** @test */ - public function it_will_return_inital_patch_value_where_version_is_null_or_empty_or_false(){ + /** @test */ + public function it_will_return_inital_bump_value_where_version_is_null_or_empty_or_false() + { + $bumper = new Bumper; - $bumper = new Bumper; + $versionNull = $bumper->bump(null)->get(); + $this->assertEquals('0.0.1', $versionNull); - $versionNull = $bumper->bumpPatch(null)->get(); - $this->assertEquals('0.0.1',$versionNull); + $versionEmptyString = $bumper->bump(null)->get(); + $this->assertEquals('0.0.1', $versionEmptyString); - $versionEmptyString = $bumper->bumpPatch(null)->get(); - $this->assertEquals('0.0.1',$versionEmptyString); + $versionFalse = $bumper->bump(false)->get(); + $this->assertEquals('0.0.1', $versionFalse); + } - $versionFalse = $bumper->bumpPatch(false)->get(); - $this->assertEquals('0.0.1',$versionFalse); - } - - /** @test */ - public function it_will_return_inital_minor_value_where_version_is_null_or_empty_or_false(){ + /** @test */ + public function it_will_return_inital_patch_value_where_version_is_null_or_empty_or_false() + { + $bumper = new Bumper; - $bumper = new Bumper; + $versionNull = $bumper->bumpPatch(null)->get(); + $this->assertEquals('0.0.1', $versionNull); - $versionNull = $bumper->bumpMinor(null)->get(); - $this->assertEquals('0.1.0',$versionNull); + $versionEmptyString = $bumper->bumpPatch(null)->get(); + $this->assertEquals('0.0.1', $versionEmptyString); - $versionEmptyString = $bumper->bumpMinor(null)->get(); - $this->assertEquals('0.1.0',$versionEmptyString); + $versionFalse = $bumper->bumpPatch(false)->get(); + $this->assertEquals('0.0.1', $versionFalse); + } - $versionFalse = $bumper->bumpMinor(false)->get(); - $this->assertEquals('0.1.0',$versionFalse); - } + /** @test */ + public function it_will_return_inital_minor_value_where_version_is_null_or_empty_or_false() + { + $bumper = new Bumper; - /** @test */ - public function it_will_return_inital_major_value_where_version_is_null_or_empty_or_false(){ + $versionNull = $bumper->bumpMinor(null)->get(); + $this->assertEquals('0.1.0', $versionNull); - $bumper = new Bumper; + $versionEmptyString = $bumper->bumpMinor(null)->get(); + $this->assertEquals('0.1.0', $versionEmptyString); - $versionNull = $bumper->bumpMajor(null)->get(); - $this->assertEquals('1.0.0',$versionNull); + $versionFalse = $bumper->bumpMinor(false)->get(); + $this->assertEquals('0.1.0', $versionFalse); + } - $versionEmptyString = $bumper->bumpMajor(null)->get(); - $this->assertEquals('1.0.0',$versionEmptyString); + /** @test */ + public function it_will_return_inital_major_value_where_version_is_null_or_empty_or_false() + { + $bumper = new Bumper; - $versionFalse = $bumper->bumpMajor(false)->get(); - $this->assertEquals('1.0.0',$versionFalse); - } + $versionNull = $bumper->bumpMajor(null)->get(); + $this->assertEquals('1.0.0', $versionNull); + $versionEmptyString = $bumper->bumpMajor(null)->get(); + $this->assertEquals('1.0.0', $versionEmptyString); - } \ No newline at end of file + $versionFalse = $bumper->bumpMajor(false)->get(); + $this->assertEquals('1.0.0', $versionFalse); + } +} diff --git a/tests/FileHelperTest.php b/tests/FileHelperTest.php index 4a0fec8..a88e9ca 100644 --- a/tests/FileHelperTest.php +++ b/tests/FileHelperTest.php @@ -1,118 +1,128 @@ -'a value', - 'version'=>'1.0.0', - 'another thing'=>'some other value' - ]; - - protected $initDataNoVersion = [ - 'something'=>'a value', - 'other'=>'x y z', - 'another thing'=>'some other value' - ]; - - protected $initDataInvalidFile = "[ +/** + * Class FileHelperTest + * + * @package Tests + */ +class FileHelperTest extends PHPUnit_Framework_TestCase +{ + protected $initData = [ + 'something' => 'a value', + 'version' => '1.0.0', + 'another thing' => 'some other value' + ]; + + protected $initDataNoVersion = [ + 'something' => 'a value', + 'other' => 'x y z', + 'another thing' => 'some other value' + ]; + + protected $initDataInvalidFile = "[ 'something'=>'a value',[]] 'version'=>'1.0.0',, 'another thing'=>'some other value' ]"; - protected $testFileName = 'test-dir/composer.json'; - protected $testFileNameBackup = 'test-dir/composer.json-backup'; - protected $testFileNameVFS = 'vfs://test-dir/composer.json'; + protected $testFileName = 'test-dir/composer.json'; + protected $testFileNameBackup = 'test-dir/composer.json-backup'; + protected $testFileNameVFS = 'vfs://test-dir/composer.json'; - public function setTestingFile($fileData) - { - - $this->root = vfsStream::setup(dirname($this->testFileName)); + /** + * Set Testing File + * + * @param $fileData + */ + public function setTestingFile($fileData) + { - $file = vfsStream::newFile(basename($this->testFileName)); + $this->root = vfsStream::setup(dirname($this->testFileName)); - $content = json_encode($fileData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + $file = vfsStream::newFile(basename($this->testFileName)); - $file->setContent($content); + $content = json_encode($fileData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - $this->root->addChild($file); + $file->setContent($content); - $file = vfsStream::newFile(basename($this->testFileNameBackup)); + $this->root->addChild($file); - $content = json_encode($fileData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + $file = vfsStream::newFile(basename($this->testFileNameBackup)); - $file->setContent($content); + $content = json_encode($fileData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - $this->root->addChild($file); + $file->setContent($content); - } + $this->root->addChild($file); + } - /** @test */ - public function it_will_read_version_and_return_version_from_file(){ - $this->setTestingFile($this->initData); - $version = (new FileHelper($this->testFileNameVFS))->getVersion(); + /** @test */ + public function it_will_read_version_and_return_version_from_file() + { + $this->setTestingFile($this->initData); - $this->assertEquals('1.0.0',$version); - } + $version = (new FileHelper($this->testFileNameVFS))->getVersion(); - /** @test */ - public function it_will_read_version_and_return_null_when_no_version_int_file(){ - $this->setTestingFile($this->initDataNoVersion); + $this->assertEquals('1.0.0', $version); + } - $version = (new FileHelper($this->testFileNameVFS))->getVersion(); + /** @test */ + public function it_will_read_version_and_return_null_when_no_version_int_file() + { + $this->setTestingFile($this->initDataNoVersion); - $this->assertEquals(null,$version); - } + $version = (new FileHelper($this->testFileNameVFS))->getVersion(); - /** @test */ - public function it_will_will_write_new_version(){ - $this->setTestingFile($this->initDataNoVersion); + $this->assertEquals(null, $version); + } - $testVersion = '1.2.3'; - $FileHelper = new FileHelper($this->testFileNameVFS); + /** @test */ + public function it_will_will_write_new_version() + { + $this->setTestingFile($this->initDataNoVersion); - $versionOld = $FileHelper->getVersion(); + $testVersion = '1.2.3'; + $FileHelper = new FileHelper($this->testFileNameVFS); - $versionWrite = $FileHelper->setVersion($testVersion)->writeFile()->getVersion(); + $versionOld = $FileHelper->getVersion(); - $versionRead = (new FileHelper($this->testFileNameVFS))->getVersion(); - - $this->assertNotEquals($versionRead,$versionOld); + $versionWrite = $FileHelper->setVersion($testVersion)->writeFile()->getVersion(); - $this->assertEquals($testVersion,$versionRead); - } + $versionRead = (new FileHelper($this->testFileNameVFS))->getVersion(); + $this->assertNotEquals($versionRead, $versionOld); - /** - * @test - * @expectedException Exception - **/ - public function it_will_thor_error_if_file_dont_exists(){ - + $this->assertEquals($testVersion, $versionRead); + } - new FileHelper('not existing file path'); - } + /** + * @test + * @expectedException Exception + **/ + public function it_will_thor_error_if_file_dont_exists() + { - /** - * @test - * @expectedException Exception - **/ - public function it_will_thor_error_if_file_has_invalid_format(){ - - $this->setTestingFile($this->initDataInvalidFile); + new FileHelper('not existing file path'); + } - new FileHelper($this->testFileNameVFS); + /** + * @test + * @expectedException Exception + **/ + public function it_will_thor_error_if_file_has_invalid_format() + { + $this->setTestingFile($this->initDataInvalidFile); - - } + new FileHelper($this->testFileNameVFS); + } }