Skip to content

Commit 3a8cf9a

Browse files
committed
Remove config file
1 parent 9da1ef0 commit 3a8cf9a

14 files changed

+19
-29
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
# JIRA plugin
1111
atlassian-ide-plugin.xml
1212

13-
config.json
1413
*.pem

config.json.sample

-4
This file was deleted.

index.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Set up include path for source handling
44
*/
55
set_include_path(get_include_path().":".__DIR__.'/src/');
6-
$config = json_decode(file_get_contents(__DIR__."/config.json"));
76

87
/**
98
* Set up required classes (with the autoloader)

src/PHPDraft/Parse/Drafter.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class Drafter
1717
*/
1818
public $json;
1919
/**
20-
* Configuration
20+
* Temp directory
2121
*
2222
* @var array
2323
*/
24-
protected $config;
24+
protected $tmp_dir;
2525
/**
2626
* The API Blueprint input
2727
*
@@ -43,15 +43,15 @@ class Drafter
4343
*/
4444
public function __construct($apib)
4545
{
46-
global $config;
47-
$this->config = &$config;
4846
$this->apib = $apib;
4947

5048
if (!$this->location())
5149
{
5250
throw new \RuntimeException("Drafter was not installed!", 1);
5351
}
5452
$this->drafter = $this->location();
53+
54+
$this->tmp_dir = sys_get_temp_dir().'/drafter';
5555
}
5656

5757
/**
@@ -74,21 +74,19 @@ function location()
7474
*/
7575
public function parseToJson()
7676
{
77-
$tmp_dir = $this->config->tmpdir;
78-
79-
if (!file_exists($tmp_dir))
77+
if (!file_exists($this->tmp_dir))
8078
{
81-
mkdir($tmp_dir);
79+
mkdir($this->tmp_dir);
8280
}
8381

84-
file_put_contents($tmp_dir . '/index.apib', $this->apib);
82+
file_put_contents($this->tmp_dir . '/index.apib', $this->apib);
8583

86-
shell_exec($this->drafter . ' ' . $tmp_dir . '/index.apib -f json -o ' . $tmp_dir . '/index.json 2> /dev/null');
87-
$this->json = json_decode(file_get_contents($tmp_dir . '/index.json'));
84+
shell_exec($this->drafter . ' ' . $this->tmp_dir . '/index.apib -f json -o ' . $this->tmp_dir . '/index.json 2> /dev/null');
85+
$this->json = json_decode(file_get_contents($this->tmp_dir . '/index.json'));
8886

8987
if (json_last_error() !== JSON_ERROR_NONE)
9088
{
91-
file_put_contents('php://stdout', "ERROR: invalid json in " . $tmp_dir . '/index.json');
89+
file_put_contents('php://stdout', "ERROR: invalid json in " . $this->tmp_dir . '/index.json');
9290
throw new \RuntimeException("Drafter generated invalid JSON (" . json_last_error_msg() . ")", 2);
9391
}
9492

src/PHPDraft/Parse/Tests/DrafterTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class DrafterTest extends TestBase
2424
*/
2525
public function setUp()
2626
{
27-
global $config;
28-
$config->tmpdir = TEST_STATICS;
27+
$this->mock_function('sys_get_temp_dir', 'return "'.TEST_STATICS.'";');
2928
$this->mock_function('shell_exec', 'return "/some/dir/drafter\n";');
30-
$this->class = new Drafter(file_get_contents(TEST_STATICS . '/apib'));
29+
$this->class = new Drafter(file_get_contents(TEST_STATICS . '/drafter/apib'));
3130
$this->reflection = new ReflectionClass('PHPDraft\Parse\Drafter');
3231
$this->unmock_function('shell_exec');
32+
$this->unmock_function('sys_get_temp_dir');
3333
}
3434

3535
/**
@@ -48,7 +48,7 @@ public function testSetupCorrectly()
4848
{
4949
$property = $this->reflection->getProperty('apib');
5050
$property->setAccessible(TRUE);
51-
$this->assertEquals(file_get_contents(TEST_STATICS . '/apib'), $property->getValue($this->class));
51+
$this->assertEquals(file_get_contents(TEST_STATICS . '/drafter/apib'), $property->getValue($this->class));
5252
}
5353

5454
/**
@@ -65,9 +65,9 @@ public function testPreRunStringIsEmpty()
6565
public function testParseToJSON()
6666
{
6767
$this->mock_function('shell_exec', 'return "";');
68-
file_put_contents(TEST_STATICS.'/index.json', file_get_contents(TEST_STATICS.'/json'));
68+
file_put_contents(TEST_STATICS.'/drafter/index.json', file_get_contents(TEST_STATICS.'/drafter/json'));
6969
$this->class->parseToJson();
70-
$this->assertEquals(json_decode(file_get_contents(TEST_STATICS.'/json')), $this->class->json);
70+
$this->assertEquals(json_decode(file_get_contents(TEST_STATICS.'/drafter/json')), $this->class->json);
7171
$this->unmock_function('shell_exec');
7272
}
7373

@@ -82,7 +82,7 @@ public function testParseToJSON()
8282
public function testParseToJSONWithErrors()
8383
{
8484
$this->mock_function('shell_exec', 'return "";');
85-
file_put_contents(TEST_STATICS.'/index.json', file_get_contents(TEST_STATICS.'/json_errors'));
85+
file_put_contents(TEST_STATICS.'/drafter/index.json', file_get_contents(TEST_STATICS.'/drafter/json_errors'));
8686
$this->class->parseToJson();
8787
$this->expectOutputString("WARNING: ignoring unrecognized block\nWARNING: no headers specified\nWARNING: ignoring unrecognized block\nWARNING: empty request message-body");
8888
$this->unmock_function('shell_exec');

src/PHPDraft/Parse/Tests/JsonToHTMLTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class JsonToHTMLTest extends PHPUnit_Framework_TestCase
3131
*/
3232
public function setUp()
3333
{
34-
$this->class = new JsonToHTML(json_decode(file_get_contents(TEST_STATICS . '/json')));
34+
$this->class = new JsonToHTML(json_decode(file_get_contents(TEST_STATICS . '/drafter/json')));
3535
$this->reflection = new ReflectionClass('PHPDraft\Parse\JsonToHTML');
3636
}
3737

@@ -51,7 +51,7 @@ public function testSetupCorrectly()
5151
{
5252
$property = $this->reflection->getProperty('object');
5353
$property->setAccessible(TRUE);
54-
$this->assertEquals(json_decode(file_get_contents(TEST_STATICS . '/json')), $property->getValue($this->class));
54+
$this->assertEquals(json_decode(file_get_contents(TEST_STATICS . '/drafter/json')), $property->getValue($this->class));
5555
}
5656

5757
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test.bootstrap.inc.php

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
// Load and setup class file autloader
2525
require_once 'PHPDraft/Core/Autoloader.php';
2626

27-
$config = json_decode(file_get_contents($base."/config.json"));
28-
2927
if (defined('TEST_STATICS') === FALSE)
3028
{
3129
define('TEST_STATICS', __DIR__ . '/statics');

0 commit comments

Comments
 (0)