Skip to content

Commit 79029f9

Browse files
committedSep 1, 2018
Intialize Util Composer, Git and Metadata tests
1 parent 14fb575 commit 79029f9

File tree

5 files changed

+206
-0
lines changed

5 files changed

+206
-0
lines changed
 

‎tests/Util/ComposerTest.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHINT package.
5+
*
6+
* (c) Jitendra Adhikari <jiten.adhikary@gmail.com>
7+
* <https://github.com/adhocore>
8+
*
9+
* Licensed under MIT license.
10+
*/
11+
12+
namespace Ahc\Phint\Test;
13+
14+
use Ahc\Phint\Util\Composer;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class ComposerTest extends TestCase
18+
{
19+
public function testCreateProjectOnWithoutComposerBinary()
20+
{
21+
$composer = new Composer;
22+
$composer->withWorkDir(sys_get_temp_dir());
23+
$result = $composer->createProject('project-name', 'app-name');
24+
25+
$this->assertInstanceOf(Composer::class, $result);
26+
$this->assertFalse($result->successful());
27+
}
28+
29+
public function testInstallOnWithoutComposerBinary()
30+
{
31+
$composer = new Composer;
32+
$composer->withWorkDir(sys_get_temp_dir());
33+
$result = $composer->install();
34+
35+
$this->assertInstanceOf(Composer::class, $result);
36+
$this->assertFalse($result->successful());
37+
}
38+
39+
public function testUpdateOnWithoutComposerBinary()
40+
{
41+
$composer = new Composer;
42+
$composer->withWorkDir(sys_get_temp_dir());
43+
$result = $composer->update();
44+
45+
$this->assertInstanceOf(Composer::class, $result);
46+
$this->assertFalse($result->successful());
47+
}
48+
49+
public function testDumpAutoloadOnWithoutComposerBinary()
50+
{
51+
$composer = new Composer;
52+
$composer->withWorkDir(sys_get_temp_dir());
53+
$result = $composer->dumpAutoload();
54+
55+
$this->assertInstanceOf(Composer::class, $result);
56+
$this->assertFalse($result->successful());
57+
}
58+
59+
public function testConfigOnNullDefaultValue()
60+
{
61+
$composer = new Composer;
62+
$composer->withWorkDir(sys_get_temp_dir());
63+
64+
$this->assertNull($composer->config('name'));
65+
}
66+
67+
public function testConfigOnDefaultValue()
68+
{
69+
copy(__DIR__ . '/../../composer.json', sys_get_temp_dir() . '/composer.json');
70+
$composer = new Composer;
71+
$composer->withWorkDir(sys_get_temp_dir());
72+
73+
$this->assertSame('app/name', $composer->config('name.license', 'app/name'));
74+
}
75+
}

‎tests/Util/GitTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHINT package.
5+
*
6+
* (c) Jitendra Adhikari <jiten.adhikary@gmail.com>
7+
* <https://github.com/adhocore>
8+
*
9+
* Licensed under MIT license.
10+
*/
11+
12+
namespace Ahc\Phint\Test;
13+
14+
use Ahc\Phint\Util\Git;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class GitTest extends TestCase
18+
{
19+
public function testGetConfig()
20+
{
21+
$git = new Git;
22+
23+
$this->assertArraySubset([
24+
'core.repositoryformatversion' => '0',
25+
'core.filemode' => 'true',
26+
'core.bare' => 'false',
27+
'core.logallrefupdates' => 'true',
28+
'remote.origin.url' => 'https://github.com/adhocore/phint.git',
29+
'remote.origin.fetch' => '+refs/heads/master:refs/remotes/origin/master',
30+
'' => '',
31+
], $git->getConfig());
32+
}
33+
34+
public function testGetConfigOnSpecificKey()
35+
{
36+
$git = new Git;
37+
38+
$this->assertSame('false', $git->getConfig('core.bare'));
39+
}
40+
41+
public function testInit()
42+
{
43+
$git = new Git();
44+
45+
$this->assertInstanceOf(Git::class, $git->init());
46+
$this->assertTrue($git->successful());
47+
}
48+
49+
public function testAddRemote()
50+
{
51+
$git = new Git();
52+
53+
$this->assertInstanceOf(Git::class, $git->addRemote('adhocore', 'phint'));
54+
$this->assertFalse($git->successful());
55+
}
56+
}

‎tests/Util/InflectorTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public function testStuldyCase()
2323
$this->assertEquals('ThisWillBeUcwordString', $inflector->stuldyCase('this-will-be-ucword-string'));
2424
}
2525

26+
public function testSnakeCase()
27+
{
28+
$inflector = new Inflector;
29+
30+
$this->assertEquals('this_will_be_snake_case_string', $inflector->snakeCase('this will be snake case string'));
31+
}
32+
2633
public function testWords()
2734
{
2835
$inflector = new Inflector;

‎tests/Util/MetadataTest.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHINT package.
5+
*
6+
* (c) Jitendra Adhikari <jiten.adhikary@gmail.com>
7+
* <https://github.com/adhocore>
8+
*
9+
* Licensed under MIT license.
10+
*/
11+
12+
namespace Ahc\Phint\Test;
13+
14+
use Ahc\Phint\Util\Metadata;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class MetadataTest extends TestCase
18+
{
19+
public function testForClass()
20+
{
21+
$metaData = new Metadata;
22+
$result = $metaData->forClass(Metadata::class);
23+
24+
$this->assertArraySubset([
25+
'namespace' => 'Ahc\Phint\Util',
26+
'classFqcn' => 'Ahc\Phint\Util\Metadata',
27+
'name' => 'Metadata',
28+
'className' => 'Metadata',
29+
'isTrait' => false,
30+
'isAbstract' => false,
31+
'isInterface' => false,
32+
'newable' => true,
33+
'title' => null,
34+
'texts' => [],
35+
'methods' => [],
36+
'name' => 'Metadata',
37+
], $result);
38+
}
39+
40+
public function testForMethod()
41+
{
42+
$metaData = new Metadata;
43+
$result = $metaData->forMethod(Metadata::class, 'forClass');
44+
45+
$this->assertSame([
46+
'name' => 'forClass',
47+
'inClass' => 'Ahc\Phint\Util\Metadata',
48+
'isStatic' => false,
49+
'isFinal' => false,
50+
'isPublic' => true,
51+
'isAbstract' => false,
52+
'maybeMagic' => false,
53+
'title' => null,
54+
'texts' => [],
55+
'params' => [
56+
'string $classFqcn',
57+
],
58+
'return' => 'array',
59+
], $result);
60+
}
61+
}

‎tests/Util/PathTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public function testGetPhintPath()
8181
$this->assertContains('/home', $path->getPhintPath('/fixtures'));
8282
}
8383

84+
public function testGetPhintPathOnEmptySubPath()
85+
{
86+
$path = new Path;
87+
88+
$this->assertContains('', $path->getPhintPath());
89+
}
90+
8491
public function testWriteFile()
8592
{
8693
$writeFilePath = __DIR__ . '/../fixtures/write_file.txt';

0 commit comments

Comments
 (0)
Please sign in to comment.