Skip to content

Commit

Permalink
Intialize Util Composer, Git and Metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Sep 1, 2018
1 parent 14fb575 commit 79029f9
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/Util/ComposerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of the PHINT package.
*
* (c) Jitendra Adhikari <[email protected]>
* <https://github.com/adhocore>
*
* Licensed under MIT license.
*/

namespace Ahc\Phint\Test;

use Ahc\Phint\Util\Composer;
use PHPUnit\Framework\TestCase;

class ComposerTest extends TestCase
{
public function testCreateProjectOnWithoutComposerBinary()
{
$composer = new Composer;
$composer->withWorkDir(sys_get_temp_dir());
$result = $composer->createProject('project-name', 'app-name');

$this->assertInstanceOf(Composer::class, $result);
$this->assertFalse($result->successful());
}

public function testInstallOnWithoutComposerBinary()
{
$composer = new Composer;
$composer->withWorkDir(sys_get_temp_dir());
$result = $composer->install();

$this->assertInstanceOf(Composer::class, $result);
$this->assertFalse($result->successful());
}

public function testUpdateOnWithoutComposerBinary()
{
$composer = new Composer;
$composer->withWorkDir(sys_get_temp_dir());
$result = $composer->update();

$this->assertInstanceOf(Composer::class, $result);
$this->assertFalse($result->successful());
}

public function testDumpAutoloadOnWithoutComposerBinary()
{
$composer = new Composer;
$composer->withWorkDir(sys_get_temp_dir());
$result = $composer->dumpAutoload();

$this->assertInstanceOf(Composer::class, $result);
$this->assertFalse($result->successful());
}

public function testConfigOnNullDefaultValue()
{
$composer = new Composer;
$composer->withWorkDir(sys_get_temp_dir());

$this->assertNull($composer->config('name'));
}

public function testConfigOnDefaultValue()
{
copy(__DIR__ . '/../../composer.json', sys_get_temp_dir() . '/composer.json');
$composer = new Composer;
$composer->withWorkDir(sys_get_temp_dir());

$this->assertSame('app/name', $composer->config('name.license', 'app/name'));
}
}
56 changes: 56 additions & 0 deletions tests/Util/GitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the PHINT package.
*
* (c) Jitendra Adhikari <[email protected]>
* <https://github.com/adhocore>
*
* Licensed under MIT license.
*/

namespace Ahc\Phint\Test;

use Ahc\Phint\Util\Git;
use PHPUnit\Framework\TestCase;

class GitTest extends TestCase
{
public function testGetConfig()
{
$git = new Git;

$this->assertArraySubset([
'core.repositoryformatversion' => '0',
'core.filemode' => 'true',
'core.bare' => 'false',
'core.logallrefupdates' => 'true',
'remote.origin.url' => 'https://github.com/adhocore/phint.git',
'remote.origin.fetch' => '+refs/heads/master:refs/remotes/origin/master',
'' => '',
], $git->getConfig());
}

public function testGetConfigOnSpecificKey()
{
$git = new Git;

$this->assertSame('false', $git->getConfig('core.bare'));
}

public function testInit()
{
$git = new Git();

$this->assertInstanceOf(Git::class, $git->init());
$this->assertTrue($git->successful());
}

public function testAddRemote()
{
$git = new Git();

$this->assertInstanceOf(Git::class, $git->addRemote('adhocore', 'phint'));
$this->assertFalse($git->successful());
}
}
7 changes: 7 additions & 0 deletions tests/Util/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public function testStuldyCase()
$this->assertEquals('ThisWillBeUcwordString', $inflector->stuldyCase('this-will-be-ucword-string'));
}

public function testSnakeCase()
{
$inflector = new Inflector;

$this->assertEquals('this_will_be_snake_case_string', $inflector->snakeCase('this will be snake case string'));
}

public function testWords()
{
$inflector = new Inflector;
Expand Down
61 changes: 61 additions & 0 deletions tests/Util/MetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the PHINT package.
*
* (c) Jitendra Adhikari <[email protected]>
* <https://github.com/adhocore>
*
* Licensed under MIT license.
*/

namespace Ahc\Phint\Test;

use Ahc\Phint\Util\Metadata;
use PHPUnit\Framework\TestCase;

class MetadataTest extends TestCase
{
public function testForClass()
{
$metaData = new Metadata;
$result = $metaData->forClass(Metadata::class);

$this->assertArraySubset([
'namespace' => 'Ahc\Phint\Util',
'classFqcn' => 'Ahc\Phint\Util\Metadata',
'name' => 'Metadata',
'className' => 'Metadata',
'isTrait' => false,
'isAbstract' => false,
'isInterface' => false,
'newable' => true,
'title' => null,
'texts' => [],
'methods' => [],
'name' => 'Metadata',
], $result);
}

public function testForMethod()
{
$metaData = new Metadata;
$result = $metaData->forMethod(Metadata::class, 'forClass');

$this->assertSame([
'name' => 'forClass',
'inClass' => 'Ahc\Phint\Util\Metadata',
'isStatic' => false,
'isFinal' => false,
'isPublic' => true,
'isAbstract' => false,
'maybeMagic' => false,
'title' => null,
'texts' => [],
'params' => [
'string $classFqcn',
],
'return' => 'array',
], $result);
}
}
7 changes: 7 additions & 0 deletions tests/Util/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public function testGetPhintPath()
$this->assertContains('/home', $path->getPhintPath('/fixtures'));
}

public function testGetPhintPathOnEmptySubPath()
{
$path = new Path;

$this->assertContains('', $path->getPhintPath());
}

public function testWriteFile()
{
$writeFilePath = __DIR__ . '/../fixtures/write_file.txt';
Expand Down

0 comments on commit 79029f9

Please sign in to comment.