Skip to content
This repository was archived by the owner on Jul 26, 2019. It is now read-only.

Commit

Permalink
End DB Connect and Start Real Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thabet-Do committed Apr 19, 2019
1 parent b39024a commit 54e3580
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 105 deletions.
10 changes: 0 additions & 10 deletions .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

233 changes: 156 additions & 77 deletions .idea/workspace.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Controller;


use App\Entity\Product;
use Michelf\MarkdownInterface;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -69,4 +71,12 @@ public function togglenArticleHart($slug, LoggerInterface $logger)

return new JsonResponse(['hart' => rand(5,100)]);
}

/**
* @Route("/show/{id}")
*/
public function showProduct(Product $product)
{
return new Response();
}
}
26 changes: 22 additions & 4 deletions src/Controller/ProductController.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php

// src/Controller/ProductController.php
namespace App\Controller;

// ...
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

use App\Entity\Product;
use Symfony\Component\Routing\Annotation\Route;

class ProductController extends AbstractController
Expand All @@ -12,8 +17,21 @@ class ProductController extends AbstractController
*/
public function index()
{
return $this->render('product/index.html.twig', [
'controller_name' => 'ProductController',
]);
// you can fetch the EntityManager via $this->getDoctrine()
// or you can add an argument to your action: index(EntityManagerInterface $entityManager)
$entityManager = $this->getDoctrine()->getManager();

$product = new Product();
$product->setName('Keyboard');
$product->setPrice(1999);
$product->setDescription('Ergonomic and stylish!');

// tell Doctrine you want to (eventually) save the Product (no queries yet)
$entityManager->persist($product);

// actually executes the queries (i.e. the INSERT query)
$entityManager->flush();

return new Response('Saved new product with id '.$product->getId());
}
}
}
35 changes: 35 additions & 0 deletions src/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ class Product
*/
private $name;

/**
* @ORM\Column(type="integer", nullable=true)
*/
private $price;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;

public function getId(): ?int
{
return $this->id;
Expand All @@ -37,4 +47,29 @@ public function setName(?string $name): self

return $this;
}

public function getPrice(): ?int
{
return $this->price;
}

public function setPrice(?int $price): self
{
$this->price = $price;

return $this;
}

public function getDescription(): ?string
{
return $this->description;
}

public function setDescription(?string $description): self
{
$this->description = $description;

return $this;
}

}
35 changes: 35 additions & 0 deletions src/Migrations/Version20190418155224.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190418155224 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE product ADD description LONGTEXT NOT NULL');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE product DROP description');
}
}
35 changes: 35 additions & 0 deletions src/Migrations/Version20190418155443.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190418155443 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE product ADD description LONGTEXT NOT NULL, ADD price INT DEFAULT NULL');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE product DROP description, DROP price');
}
}
35 changes: 35 additions & 0 deletions src/Migrations/Version20190418165656.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190418165656 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE product ADD price INT DEFAULT NULL, ADD description VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE product DROP price, DROP description');
}
}

0 comments on commit 54e3580

Please sign in to comment.