Skip to content

Commit 1d33b43

Browse files
committed
Merge branch 'dev' of https://github.com/WebFiori/framework into dev
2 parents 852c2db + 5262b6c commit 1d33b43

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</p>
66

77
<p align="center">
8-
<a href="https://github.com/WebFiori/framework/actions"><img src="https://github.com/WebFiori/framework/actions/workflows/php84.yml/badge.svg?branch=master"></a>
8+
<a href="https://github.com/WebFiori/framework/actions"><img src="https://github.com/WebFiori/framework/actions/workflows/php84.yml/badge.svg?branch=main"></a>
99
<a href="https://codecov.io/gh/WebFiori/framework">
1010
<img src="https://codecov.io/gh/WebFiori/framework/branch/master/graph/badge.svg" />
1111
</a>
@@ -29,11 +29,11 @@ WebFiori Framework is a mini web development framework which is built using PHP
2929
## Supported PHP Versions
3030
| Build Status |
3131
|:-----------:|
32-
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php80.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php80.yml/badge.svg?branch=master"></a>|
33-
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php81.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php81.yml/badge.svg?branch=master"></a>|
34-
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php82.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php82.yml/badge.svg?branch=master"></a>|
35-
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php83.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php83.yml/badge.svg?branch=master"></a>|
36-
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php84.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php84.yml/badge.svg?branch=master"><br>|
32+
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php80.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php80.yml/badge.svg?branch=main"></a>|
33+
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php81.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php81.yml/badge.svg?branch=main"></a>|
34+
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php82.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php82.yml/badge.svg?branch=main"></a>|
35+
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php83.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php83.yml/badge.svg?branch=main"></a>|
36+
|<a target="_blank" href="https://github.com/WebFiori/framework/actions/workflows/php84.yml"><img src="https://github.com/WebFiori/framework/actions/workflows/php84.yml/badge.svg?branch=main"></a><br>|
3737

3838

3939
## Key Features
@@ -62,6 +62,7 @@ Following table shows build status of the standard libraries that the framework
6262
| Library | Build | Latest |
6363
|----|----|----|
6464
| [HTTP](https://github.com/WebFiori/http) | <a href="https://github.com/WebFiori/http/actions"><img src="https://github.com/WebFiori/http/actions/workflows/php83.yml/badge.svg?branch=master"></a> | <a href="https://github.com/WebFiori/http/releases"><img src="https://img.shields.io/github/release/WebFiori/http.svg" /></a> |
65+
| [Cache](https://github.com/WebFiori/cache) | <a href="https://github.com/WebFiori/cache/actions"><img src="https://github.com/WebFiori/cache/actions/workflows/php84.yml/badge.svg?branch=main"></a> | <a href="https://github.com/WebFiori/cache/releases"><img src="https://img.shields.io/github/release/WebFiori/cache.svg" /></a> |
6566
| [File](https://github.com/WebFiori/file) | <a href="https://github.com/WebFiori/file/actions"><img src="https://github.com/WebFiori/file/actions/workflows/php83.yml/badge.svg?branch=main"></a> | <a href="https://github.com/WebFiori/file/releases"><img src="https://img.shields.io/github/release/WebFiori/file.svg" /></a> |
6667
| [Json](https://github.com/WebFiori/json) | <a href="https://github.com/WebFiori/json/actions"><img src="https://github.com/WebFiori/json/actions/workflows/php83.yml/badge.svg?branch=master"></a> | <a href="https://github.com/WebFiori/json/releases"><img src="https://img.shields.io/github/release/WebFiori/json.svg" /></a> |
6768
| [UI](https://github.com/WebFiori/ui) | <a href="https://github.com/WebFiori/ui/actions"><img src="https://github.com/WebFiori/ui/actions/workflows/php83.yml/badge.svg?branch=master"></a> | <a href="https://github.com/WebFiori/ui/releases"><img src="https://img.shields.io/github/release/WebFiori/ui.svg" /></a> |

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

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

4-
use PHPUnit\Framework\TestCase;
4+
use webfiori\cli\CommandTestCase;
55
use webfiori\cli\Runner;
66
use webfiori\file\File;
77
use webfiori\framework\App;
@@ -13,30 +13,32 @@
1313
*
1414
* @author Ibrahim
1515
*/
16-
class AddCommandTest extends TestCase {
16+
class AddCommandTest extends CommandTestCase {
1717
/**
1818
* @test
1919
*/
2020
public function test00() {
21+
$output = $this->executeSingleCommand(new AddCommand(), [], [
22+
'3'
23+
]);
2124
$runner = new Runner();
2225
$runner->setInputs([
2326
'3'
2427
]);
25-
$this->assertEquals(0, $runner->runCommand(new AddCommand()));
2628
$this->assertEquals([
2729
"What would you like to add?\n",
2830
"0: New database connection.\n",
2931
"1: New SMTP connection.\n",
3032
"2: New website language.\n",
3133
"3: Quit. <--\n"
32-
], $runner->getOutput());
34+
], $output);
35+
$this->assertEquals(0, $this->getExitCode());
3336
}
3437
/**
3538
* @test
3639
*/
3740
public function testAddDBConnection00() {
38-
$runner = App::getRunner();
39-
$runner->setInputs([
41+
$output = $this->executeSingleCommand(new AddCommand(), [], [
4042
'0',
4143
'0',
4244
'127.0.0.1',
@@ -46,11 +48,8 @@ public function testAddDBConnection00() {
4648
'testing_db',
4749
''
4850
]);
49-
$runner->setArgsVector([
50-
'webfiori',
51-
'add'
52-
]);
53-
$this->assertEquals(0, $runner->start());
51+
52+
5453
$connName = 'db-connection-'.(count(App::getConfig()->getDBConnections()) - 1);
5554
$this->assertEquals([
5655
"What would you like to add?\n",
@@ -70,7 +69,8 @@ public function testAddDBConnection00() {
7069
"Trying to connect to the database...\n",
7170
"Success: Connected. Adding the connection...\n",
7271
"Success: Connection information was stored in application configuration.\n"
73-
], $runner->getOutput());
72+
], $output);
73+
$this->assertEquals(0, $this->getExitCode());
7474
}
7575
/**
7676
* @test
@@ -111,8 +111,9 @@ public function testAddDBConnection01() {
111111
"Database name:\n",
112112
"Give your connection a friendly name: Enter = '$connName'\n",
113113
"Trying to connect to the database...\n",
114+
"Trying with 'localhost'...\n",
114115
"Error: Unable to connect to the database.\n",
115-
"Error: Unable to connect to database: 2002 - No such file or directory\n",
116+
"Error: Unable to connect to database: 1045 - Access denied for user 'root'@'localhost' (using password: YES)\n",
116117
"Would you like to store connection information anyway?(y/N)\n",
117118
"Success: Connection information was stored in application configuration.\n"
118119
], $runner->getOutput());
@@ -155,8 +156,9 @@ public function testAddDBConnection02() {
155156
"Database name:\n",
156157
"Give your connection a friendly name: Enter = '$connName'\n",
157158
"Trying to connect to the database...\n",
159+
"Trying with 'localhost'...\n",
158160
"Error: Unable to connect to the database.\n",
159-
"Error: Unable to connect to database: 2002 - No such file or directory\n",
161+
"Error: Unable to connect to database: 1045 - Access denied for user 'root'@'localhost' (using password: YES)\n",
160162
"Would you like to store connection information anyway?(y/N)\n",
161163
], $runner->getOutput());
162164
}

webfiori/framework/cli/commands/AddCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ private function addDbConnection(): int {
7575
$this->println('Trying to connect to the database...');
7676

7777
$addConnection = $this->tryConnect($connInfoObj);
78-
78+
$orgHost = $connInfoObj->getHost();
79+
$orgErr = $addConnection !== true ? $addConnection->getMessage() : '';
80+
7981
if ($addConnection !== true) {
8082
if ($connInfoObj->getHost() == '127.0.0.1') {
83+
$this->println("Trying with 'localhost'...");
8184
$connInfoObj->setHost('localhost');
8285
$addConnection = $this->tryConnect($connInfoObj);
8386
} else if ($connInfoObj->getHost() == 'localhost') {
87+
$this->println("Trying with '127.0.0.1'...");
8488
$connInfoObj->setHost('127.0.0.1');
8589
$addConnection = $this->tryConnect($connInfoObj);
8690
}
@@ -92,8 +96,9 @@ private function addDbConnection(): int {
9296
App::getConfig()->addOrUpdateDBConnection($connInfoObj);
9397
$this->success('Connection information was stored in application configuration.');
9498
} else {
99+
$connInfoObj->setHost($orgHost);
95100
$this->error('Unable to connect to the database.');
96-
$this->error($addConnection->getMessage());
101+
$this->error($orgErr);
97102
$this->confirmAdd($connInfoObj);
98103
}
99104

0 commit comments

Comments
 (0)