hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Symfony 3 Establish a test database for integration testing

In Symofny it is called automatically when you run tests app/config/parameters_test.yml loaded.
There, another database should then be specified, for simplicity sake with the same database user:

database_host: same_as_dev
database_port: same_as_dev
database_name: test_db
database_user: same_as_dev
database_password: same_as_dev

Then following commands must be executed on the console:
Clear cache:
am PHP / console cache:clear –env = test

Create database
am PHP / console doctrine:database:create –env = test

Create tables
HP am / console doctrine:schema:update –env = test –force

Then can fixtures are loaded and integration tests are written.

 

hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Load configuration within the bundle bundle

So the bundle independently funktioneiren and to avoid dependencies, should his own configurations a bundle include

e.g.. : src/MyBundle/Resources/config/config.yml

but also Download your own.

Uploading the configuration is via the DependencyInjection container possible.

Example:

To load the following config. It contains its own bundle parameters and use extension parameters:

my_bundle:   #Naming Convention!
  modules:

extension_x:
  param: "foo.html.twig"

It must 2 Files are created:

src/MyBundle/DependencyInjection/MyExtension.php: more…

hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Syfmony 3.3. – How to injeziert a repository as a service using dependency injection

In symfony 3 is by default the EntityManager injected, then get the corresponding repository available.

Most of the time, but just a repository is required and to bloat the code and tests.

There is a simple way in the configuration to create a service from a repository:

service.repository.name:
 class: 'AppBundle\Repository\MyEntity'
 factory: 'Doctrine\ORM\EntityManagerInterface:getRepository'
 arguments: ['AppBundle\Entity\MyEntity']
hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Testable PHP CSV Streamreader Class inklusive Shunks

class CsvReader implements ReaderInterface
{

    /**
     * shunk size for file import
     */
    private $shunkSize;

    /**
     * @param int $shunkSize
     */
    public function __construct(int $shunkSize)
    {
        $this->shunkSize = $shunkSize;
    }

    /**
     * @param string $file
     * @param callable $callback
     *
     * @return array
     * @throws StorageException
     */
    public function shunkCsvFile(string $file, callable $callback): array
    {
        $file = $this->getFileObject($file);
        $file->setFlags(
            SplFileObject::READ_CSV |
            SplFileObject::SKIP_EMPTY |
            SplFileObject::READ_AHEAD
        );

        $row = 0;
        $data = [];
        if ($file->isFile()) {
            while (!$file->eof()) {
                $line = $file->fgetcsv(';');
                $row++;
                if ($row === 1) {
                    //skip header
                    continue;
                }

                $data[] = $line;

                if (($row % $this->shunkSize) == 0) {
                    $callback($data);
                    $data = [];
                }
            }
        }

        $callback($data);
            
    }

    /**
     * @param string $file
     *
     * @return SplFileObject
     *
     * @codeCoverageIgnore
     */
    protected function getFileObject(string $file): SplFileObject
    {
        return new SplFileObject($file);
    }
hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...
hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

SSL for all and free with certbot.eff.org

HTTPS and SSL is important for any Web page and often an annoying pastime, If the certificates expire and you quickly install the current certificates.

Let is a simple and ample alternative ’ s encrypt, the free service offer not only very fast with the (5 Minutes) SSL certificates can install, Special who cares to update the certificates, they all 90 Days expire.

For this purpose you installed on the console called a client certbot, which automatically binds the certificates for the own Web server/load balancers (nginx, Apache) and later via cronjob currently holds.

A great thing, I put on the page baby taschenrechner.de in live use and am very happy.

hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...
hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Docker – an introduction

Docker is a virtualization tool, with the operating system environments and there running software in containers can be packed up and can be run on non-operating system environments.

The advantages of docker:

- Containers can be exchanged very easily with docker, This helps with the work on joint projects, If infrastructure needs to be angeapsst, only on the dev environment, then on the test environment, etc. So can run test using the appropriate environment, It therefore has a dynamic test environment, instead of a static

- performance advantages compared to virtual machines

- the containers make it easier, the development environment for software projects all participants quick and easy to make. This will make easier the onboarding and dependencies are avoided, as e.g.. a development server, work on all, which may not be altered but

- impertinent so finally environment simulates also distributed systems in development and testing and testing. This can error be earlier found and avoids. Who does not know that, the production system consists of multiple nodes behind a load balancer with master/slave database, but the dev/test/staging system has only a node without slave.

- Plattformunabhaengikeit: You can run on his MAC Windows applications in the container without any problems

Docker consists of several components: more…

hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Project: baby taschenrechner.de

The just completed project baby taschenrechner.de deals with the issues relating to the development of the own child:

  • How great my child be in x years
  • My child is like in x years
  • Is my child too hard or too thin
  • What dress size is wear it when?

The Web page is to help parents find out, When you need to buy what dress size, the approaching winter/summer home to have the appropriate.

Parents can thus einschätzne, If the child is too thin or too thick for your age/size/weight ratio.

The following technologies were used for the realization:

Symfony 3, Docker, MySQL, PHP, GIT, Google material design, Amazon AWS

hard mistakes - please write a commentsome mistakesokgoodvery good
Loading ... Loading ...

Set up authentication with X-Pack for Elasticsearch

A simple http Basic authentication to set up for Elasticsearch with user name and password you need to install as the first X-Pack.

Then all functions should be automatically protected with basic auth. After the installation, a default user is available, to be able to continue working:

Name: elastic
Password: changeme

Thus, requests can be made successfully:

curl --user elastic:changeme -XGET 'localhost:9200'

Create your own user

Now can own user are added to:

curl --user elastic:changeme -XPOST 'hlocalhost:9200/_xpack/security/user/SebastianViereck?pretty' -H 'Content-Type: application/json' -d'
{
  "password" : "thePassword",
  "roles" : [ "superuser"],
  "full_name" : "Sebastian Viereck",
  "email" : "%MINIFYHTML092326abde499eb08a73fe73469cfc416%",
  "metadata" : {
    "intelligence" : 7
  },
  "enabled": true
}

After that, requests can be made immediately with the user:

curl --user SebastianViereck:thePassword -XGET 'localhost:9200'

It should own role be created and be used or how here the prefabricated rolls (superuser) be used.

Disable the elastic user

Very important: Of course, the default must user with the elastic “changeme” Password are disabled again. In the elasticsearch.yml must the the following parameters be used:

xpack.security.authc.accept_default_password: false

And the elasticsearch service be restarted:

 sudo service elasticsearch restart

To the control, an error message should appear at the request:

curl --user elastic:changeme -XGET 'localhost:9200'

More security enhancements

It should be a Data encryption be used with SSL.

The IP room, may be communicating with at all, should also be narrowed.