Skip to content

Commit 58912d1

Browse files
authored
Merge pull request #165 from WebFiori/dev
Quality Improvments
2 parents deb4079 + fba6267 commit 58912d1

File tree

72 files changed

+787
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+787
-590
lines changed

bootstrap.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393
//run code after tests completion.
9494
register_shutdown_function(function()
9595
{
96-
$sessionDb = new webfiori\framework\session\DatabaseSessionStorage();
97-
$sessionDb->dropTables();
9896
ConfigController::get()->removeConfigFiles();
9997
});
10098
fprintf(STDOUT, "Registering shutdown function completed.\n");

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"require": {
1616
"php": ">=7.0",
1717
"webfiori/err":"v1.0.5",
18-
"webfiori/cli":"v1.0.8",
18+
"webfiori/cli":"v1.0.10",
1919
"webfiori/file":"v1.2.2",
2020
"webfiori/collections":"v1.1.1",
2121
"webfiori/ui":"v2.4.0",
2222
"webfiori/jsonx":"v3.1.5",
23+
"webfiori/http":"v3.2.20 ",
2324
"webfiori/database":"v0.5.4",
24-
"webfiori/http":"v3.2.18 ",
2525
"webfiori/mailer":"v1.0.2"
2626
},
2727
"require-dev": {

tests/tables/Schema.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
namespace tables;
5+
6+
use webfiori\framework\DB;
7+
/**
8+
* Description of Schema
9+
*
10+
* @author Ibrahim
11+
*/
12+
class Schema extends DB {
13+
public function __construct() {
14+
parent::__construct('testing-connection');
15+
$this->addTable(new EmployeeInfoTable());
16+
}
17+
}

tests/tables/Schema2.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
namespace tables;
5+
6+
use webfiori\framework\DB;
7+
/**
8+
* Description of Schema
9+
*
10+
* @author Ibrahim
11+
*/
12+
class Schema2 extends DB {
13+
public function __construct() {
14+
parent::__construct('testing-connection');
15+
$this->addTable(new PositionInfoTable());
16+
}
17+
}

tests/tables/Schema3.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
namespace tables;
5+
6+
use webfiori\framework\DB;
7+
/**
8+
* Description of Schema
9+
*
10+
* @author Ibrahim
11+
*/
12+
class Schema3 extends DB {
13+
public function __construct() {
14+
parent::__construct('testing-connection');
15+
$this->addTable(new PositionInfoTable());
16+
}
17+
}

tests/webfiori/framework/test/PageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ public function testCreateHtmlNode02() {
504504
]);
505505
$this->assertEquals('section', $node->getNodeName());
506506
$this->assertEquals('super-sec', $node->getChild(0)->getID());
507+
$el = $page->getChildByID('my-div');
508+
$this->assertEquals('My Name Is Super Hero', $el->getChild(0)->getText());
507509
}
508510
/**
509511
* @test

tests/webfiori/framework/test/TestAutoLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestAutoLoader extends TestCase {
1313
* @test
1414
*/
1515
public function test00() {
16-
$this->assertEquals(ROOT_DIR, AutoLoader::root());
16+
$this->assertEquals(ROOT_PATH, AutoLoader::root());
1717
}
1818
/**
1919
* @test

tests/webfiori/framework/test/cli/AddCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function testAddLang00() {
188188
"Select writing direction:\n",
189189
"0: ltr\n",
190190
"1: rtl\n",
191-
"Success: Language added. Also, a class for the language is created at \"".APP_DIR_NAME."\langs\" for that language.\n"
191+
"Success: Language added. Also, a class for the language is created at \"".APP_DIR."\langs\" for that language.\n"
192192
], $runner->getOutput());
193193
$this->assertTrue(class_exists('\\app\\langs\\LanguageFK'));
194194
$this->removeClass('\\app\\langs\\LanguageFK');
@@ -280,7 +280,7 @@ public function testAddSMTPConnection00() {
280280
], $runner->getOutput());
281281
}
282282
private function removeClass($classPath) {
283-
$file = new File(ROOT_DIR.$classPath.'.php');
283+
$file = new File(ROOT_PATH.$classPath.'.php');
284284
$file->remove();
285285
}
286286
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace webfiori\framework\test\cli;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use webfiori\framework\cron\Cron;
7+
use webfiori\framework\WebFioriApp;
8+
/**
9+
* Description of CronCommandTest
10+
*
11+
* @author Ibrahim
12+
*/
13+
class CreateCLICommandTest extends CreateTestCase {
14+
/**
15+
* @test
16+
*/
17+
public function testCreateCommand00() {
18+
$runner = $runner = WebFioriApp::getRunner();
19+
$runner->setArgsVector([
20+
'webfiori',
21+
'create'
22+
]);
23+
$runner->setInput([
24+
'5',
25+
'NewCLI',
26+
'app\commands',
27+
'print-hello',
28+
'Prints \'Hello World\' in the console.',
29+
'N',
30+
'',
31+
]);
32+
33+
$this->assertEquals(0, $runner->start());
34+
$this->assertEquals([
35+
"What would you like to create?\n",
36+
"0: Database table class.\n",
37+
"1: Entity class from table.\n",
38+
"2: Web service.\n",
39+
"3: Background job.\n",
40+
"4: Middleware.\n",
41+
"5: CLI Command.\n",
42+
"6: Theme.\n",
43+
"7: Database access class based on table.\n",
44+
"8: Complete REST backend (Database table, entity, database access and web services).\n",
45+
"9: Quit. <--\n",
46+
"Enter a name for the new class:\n",
47+
"Enter an optional namespace for the class: Enter = 'app\commands'\n",
48+
"Enter a name for the command:\n",
49+
"Give a short description of the command:\n",
50+
"Would you like to add arguments to the command?(y/N)\n",
51+
'Info: New class was created at "'.ROOT_PATH.DS.'app'.DS."commands\".\n",
52+
], $runner->getOutput());
53+
$this->assertTrue(class_exists('\\app\\commands\\NewCLICommand'));
54+
$this->removeClass('\\app\\commands\\NewCLICommand');
55+
}
56+
/**
57+
* @test
58+
*/
59+
public function testCreateCommand01() {
60+
$runner = $runner = WebFioriApp::getRunner();
61+
$runner->setArgsVector([
62+
'webfiori',
63+
'create',
64+
'--c' => 'command'
65+
]);
66+
$runner->setInput([
67+
'DoIt',
68+
'app\commands',
69+
'do-it',
70+
'Do something amazing.',
71+
'y',
72+
'--what-to-do',
73+
"The thing that the command will do.",
74+
"y",
75+
"Say Hi",
76+
"y",
77+
"Say No",
78+
"y",
79+
"Say No",
80+
'n',
81+
'y',
82+
'',
83+
'n'
84+
]);
85+
86+
$this->assertEquals(0, $runner->start());
87+
$this->assertEquals([
88+
"Enter a name for the new class:\n",
89+
"Enter an optional namespace for the class: Enter = 'app\commands'\n",
90+
"Enter a name for the command:\n",
91+
"Give a short description of the command:\n",
92+
"Would you like to add arguments to the command?(y/N)\n",
93+
"Enter argument name:\n",
94+
"Describe this argument and how to use it: Enter = ''\n",
95+
"Does this argument have a fixed set of values?(y/N)\n",
96+
"Enter the value:\n",
97+
"Would you like to add more values?(y/N)\n",
98+
"Enter the value:\n",
99+
"Would you like to add more values?(y/N)\n",
100+
"Enter the value:\n",
101+
"Info: Given value was already added.\n",
102+
"Would you like to add more values?(y/N)\n",
103+
"Is this argument optional or not?(Y/n)\n",
104+
"Enter default value:\n",
105+
"Would you like to add more arguments?(y/N)\n",
106+
'Info: New class was created at "'.ROOT_PATH.DS.'app'.DS."commands\".\n",
107+
], $runner->getOutput());
108+
$clazz = '\\app\\commands\\DoItCommand';
109+
$this->assertTrue(class_exists($clazz));
110+
$clazzObj = new $clazz();
111+
$this->assertTrue($clazzObj instanceof \webfiori\cli\CLICommand);
112+
$this->assertEquals('do-it', $clazzObj->getName());
113+
$arg = $clazzObj->getArg('--what-to-do');
114+
$this->assertNotNull($arg);
115+
$this->assertEquals([
116+
'Say Hi', 'Say No'
117+
], $arg->getAllowedValues());
118+
$this->assertTrue($arg->isOptional());
119+
$this->assertEquals('The thing that the command will do.', $arg->getDescription());
120+
$this->assertEquals('', $arg->getDefault());
121+
$this->removeClass($clazz);
122+
}
123+
}

tests/webfiori/framework/test/cli/CreateCommandTest.php

Lines changed: 6 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace webfiori\framework\test\cli;
33

4-
use webfiori\file\File;
4+
use app\database\TestTable;
55
use webfiori\framework\WebFioriApp;
66
/**
77
* Description of TestCreateCommand
@@ -65,90 +65,8 @@ public function testCreate01() {
6565
}
6666

6767

68-
/**
69-
* @test
70-
*/
71-
public function testCreateMiddleware00() {
72-
$runner = $runner = WebFioriApp::getRunner();
73-
$runner->setArgsVector([
74-
'webfiori',
75-
'create'
76-
]);
77-
$runner->setInput([
78-
'4',
79-
'NewCoolMd',
80-
'app\middleware',
81-
'Check is authorized',
82-
'22',
83-
'',
84-
'',
85-
]);
86-
87-
$this->assertEquals(0, $runner->start());
88-
$this->assertEquals([
89-
"What would you like to create?\n",
90-
"0: Database table class.\n",
91-
"1: Entity class from table.\n",
92-
"2: Web service.\n",
93-
"3: Background job.\n",
94-
"4: Middleware.\n",
95-
"5: CLI Command.\n",
96-
"6: Theme.\n",
97-
"7: Database access class based on table.\n",
98-
"8: Complete REST backend (Database table, entity, database access and web services).\n",
99-
"9: Quit. <--\n",
100-
"Enter a name for the new class:\n",
101-
"Enter an optional namespace for the class: Enter = 'app\middleware'\n",
102-
"Enter a name for the middleware:\n",
103-
"Enter middleware priority: Enter = '0'\n",
104-
"Would you like to add the middleware to a group?(y/N)\n",
105-
'Info: New class was created at "'.ROOT_DIR.DS.'app'.DS."middleware\".\n",
106-
], $runner->getOutput());
107-
$this->assertTrue(class_exists('\\app\\middleware\\NewCoolMdMiddleware'));
108-
$this->removeClass('\\app\\middleware\\NewCoolMdMiddleware');
109-
}
110-
/**
111-
* @test
112-
*/
113-
public function testCreateCommand00() {
114-
$runner = $runner = WebFioriApp::getRunner();
115-
$runner->setArgsVector([
116-
'webfiori',
117-
'create'
118-
]);
119-
$runner->setInput([
120-
'5',
121-
'NewCLI',
122-
'app\commands',
123-
'print-hello',
124-
'Prints \'Hello World\' in the console.',
125-
'N',
126-
'',
127-
]);
128-
129-
$this->assertEquals(0, $runner->start());
130-
$this->assertEquals([
131-
"What would you like to create?\n",
132-
"0: Database table class.\n",
133-
"1: Entity class from table.\n",
134-
"2: Web service.\n",
135-
"3: Background job.\n",
136-
"4: Middleware.\n",
137-
"5: CLI Command.\n",
138-
"6: Theme.\n",
139-
"7: Database access class based on table.\n",
140-
"8: Complete REST backend (Database table, entity, database access and web services).\n",
141-
"9: Quit. <--\n",
142-
"Enter a name for the new class:\n",
143-
"Enter an optional namespace for the class: Enter = 'app\commands'\n",
144-
"Enter a name for the command:\n",
145-
"Give a short description of the command:\n",
146-
"Would you like to add arguments to the command?(y/N)\n",
147-
'Info: New class was created at "'.ROOT_DIR.DS.'app'.DS."commands\".\n",
148-
], $runner->getOutput());
149-
$this->assertTrue(class_exists('\\app\\commands\\NewCLICommand'));
150-
$this->removeClass('\\app\\commands\\NewCLICommand');
151-
}
68+
69+
15270
/**
15371
* @test
15472
*/
@@ -212,7 +130,7 @@ public function testCreateWebService00() {
212130
"Success: New parameter added to the service 'get-hello'.\n",
213131
"Would you like to add another parameter?(y/N)\n",
214132
"Creating the class...\n",
215-
'Info: New class was created at "'.ROOT_DIR.DS.'app'.DS."apis\".\n",
133+
'Info: New class was created at "'.ROOT_PATH.DS.'app'.DS."apis\".\n",
216134
"Info: Don't forget to add the service to a services manager.\n",
217135
], $runner->getOutput());
218136
$this->assertTrue(class_exists('\\app\\apis\\NewWebService'));
@@ -239,7 +157,7 @@ public function testCreateEntity00() {
239157
'webfiori',
240158
'create',
241159
'--c' => 'entity',
242-
'--table' => \app\database\TestTable::class
160+
'--table' => TestTable::class
243161
]);
244162
$this->assertEquals(0, $runner->start());
245163
$this->assertEquals([
@@ -286,7 +204,7 @@ public function testCreateEntity01() {
286204
'webfiori',
287205
'create',
288206
'--c' => 'entiy',
289-
'--table' => \app\database\TestTable::class
207+
'--table' => TestTable::class
290208
]);
291209
$this->assertEquals(0, $runner->start());
292210
$this->assertEquals([

0 commit comments

Comments
 (0)