Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #286

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ INSTAGRAM_REDIRECT_URI=

MAILGUN_DOMAIN=
MAILGUN_SECRET=

GH_PAT=
2 changes: 1 addition & 1 deletion .github/workflows/feature-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Feature test
name: Run Feature tests

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Static analysis
name: Run Static analysis

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit test
name: Run Unit tests

on:
push:
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ WORKDIR /var/www

USER $user

RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/php.ini
RUN echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/php.ini
RUN echo "xdebug.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/php.ini
RUN echo "memory_limit=1024M" >> /usr/local/etc/php/conf.d/php.ini
RUN echo "allow_url_fopen=on" >> /usr/local/etc/php/conf.d/php.ini
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ db_migrate: ## run db migrations
db_schemefy: ## Display the db schema in table format
@php artisan schema:show

setup: composer generate_key
setup: composer generate_key jwt_key db_connection

copy_env: #todo: figure out a way to not override env vars if file_exists already
@cp .env.example .env
Expand All @@ -38,6 +38,12 @@ composer: ## Install project dependencies
generate_key: ## Generate APP_KEY and set in .env
@docker-compose exec app php artisan key:generate

jwt_key: ## Generate JWT_SECRET and set in .env
@docker-compose exec app php artisan jwt:secret

db_connection: ## Generate DB Connection details and set in .env
@docker-compose exec app php artisan db:connection

login: ## Creates a new user/token or generate new token for given user
@php artisan auth:token

Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: vendor/bin/heroku-php-apache2 public/
web: vendor/bin/heroku-php-nginx public/
33 changes: 33 additions & 0 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,36 @@ Examples:

![Alt text](docs/images/help.png?raw=true "help")

## Setup PHPStorm + + Docker + Xdebug + postman
- Open settings by pressing `(cmd + ,)` button
- Under PHP, add a new CLI interpreter

![add-new-cli-interpreter1.png](docs%2Fimages%2Fadd-new-cli-interpreter1.png)

- Select From Docker, Vagrant ... option
- Select Docker Compose, set the configuration file to ./docker-compose.yml and the service select app
![add-new-cli-interpreter2.png](docs%2Fimages%2Fadd-new-cli-interpreter2.png)

- Now your PHP interpreter settings hosuld look like this
![xdebug-php.png](docs%2Fimages%2Fxdebug-php.png)

- Next, you want to set up the test framework, click the plus sign and select PHPUnit by remote interpreter
![test-framework1.png](docs%2Fimages%2Ftest-framework1.png)

- Select the interpreter you just created from the dropdown list
![test-framework2.png](docs%2Fimages%2Ftest-framework2.png)

- Now you can start debugging, set a break point in any controller class and run the test associated with it in debug mode

### Listening for requests from postman
- First step is to set up a server
![server.png](docs%2Fimages%2Fserver.png)
- On postman add this parameter. When postman detects this in a request, it creates a cookie with the value of XDEBUG_SESSION_START. This has an expiry time of 30 minutes so you dont have to include it in your requests all the time.

```angular2html
XDEBUG_SESSION_START=PHPSTORM
```
- Finally, tell postman to listen for PHP Debug Connections
![php-debug-connections.png](docs%2Fimages%2Fphp-debug-connections.png)

- Set a break point in the code called by the endpoint you are consuming on postman, hit send to start debugging
19 changes: 0 additions & 19 deletions app/Adapters/Search/AlgoliaAdapter.php

This file was deleted.

10 changes: 0 additions & 10 deletions app/Adapters/Search/FulltextSearchAdapterInterface.php

This file was deleted.

145 changes: 0 additions & 145 deletions app/Adapters/Search/MySqlAdapter.php

This file was deleted.

75 changes: 75 additions & 0 deletions app/Console/Commands/DatabaseConnectionDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class DatabaseConnectionDetails extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:connection';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Reads the db connection envs from secrets';

/**
* Execute the console command.
*/
public function handle(): void
{
$connection = [
"DB_HOST" => "ao9moanwus0rjiex.cbetxkdyhwsb.us-east-1.rds.amazonaws.com",
"DB_PORT" => "3306",
"DB_DATABASE" => "athiftsxpmxaj82c",
"DB_USERNAME" => "w7dydvcjsog985xj",
"DB_PASSWORD" => "iliqkyv8vbbtw603"
];

$filepath = $this->envPath();

foreach($connection as $key => $value) {
$fileContents = $this->getFileContents($filepath);

if (Str::contains($fileContents, $key)) {
$this->putFileContents(
$filepath,
preg_replace(
"/{$key}=.*/",
"{$key}={$value}",
$fileContents
)
);
}
}

$this->info("db connection details set successfully.");
}

protected function envPath(): string
{
if (method_exists($this->laravel, 'environmentFilePath')) {
return $this->laravel->environmentFilePath();
}

return $this->laravel->basePath('.env');
}

protected function getFileContents(string $filepath): string
{
return file_get_contents($filepath);
}

protected function putFileContents(string $filepath, string $data): void
{
file_put_contents($filepath, $data);
}
}
9 changes: 6 additions & 3 deletions app/Console/Commands/LoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Console\Commands;

use App\Models\User;
use App\Services\AuthService;
use App\Services\UserService;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -39,17 +40,19 @@ public function handle(UserService $userService, AuthService $authService)

$fromCache = Cache::get('testUser');

$email = Str::random(5) . '@console.com';

if (!$fromCache) {
$this->line('User not found in Cache, creating new User ...');
$this->line('==============================================');

$response = $userService->store(new Request([
'name' => 'test user',
'email' => Str::random(5) . '@console.com',
'email' => $email,
'password' => 'testing123'
]));

$user = json_decode($response->getContent(), true)["response"]["data"];
$user = User::where('email', '=', $email)->first();

Cache::put('testUser', $user);
}
Expand All @@ -61,7 +64,7 @@ public function handle(UserService $userService, AuthService $authService)
'password' => 'testing123'
]));

$this->info($token->getContent());
$this->info($token);

$this->line('====================================');
$this->info("Here you go! Use this token to access protected resources.!");
Expand Down
4 changes: 3 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('otp:clean')
->daily()
->sentryMonitor('invalidate-otps');
}

/**
Expand Down
Loading