Subscribe: Planet PHP
http://www.planet-php.org/rss/
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
application  behat  bootstrap  code coverage  code  container  coverage data  coverage  data  entitymanager  extensions  interface  test 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Planet PHP

Planet PHP



People blogging about PHP



 



Move over Graphite, Prometheus is Here - Nomad PHP

Fri, 23 Feb 2018 15:13:49 +0000

May - EU
Presented By

Michael Heap
May 17, 2018
20:00 CEST

The post Move over Graphite, Prometheus is Here appeared first on Nomad PHP.




Installing Bolt extensions on Docker - Stefan Koopmanschap

Fri, 23 Feb 2018 13:30:00 +0000

I'm currently working on a website with the Bolt CMS. For this website, I am using an extension. Now, the "problem" with extensions is that they are installed using Composer by Bolt, and end up in the .gitignore'd vendor/ directory. Which is OK while developing, because the extension will just be in my local codebase, but once I commit my changes and push them, I run into a little problem.

Some context

Let's start with a bit of context: Our current hosting platform is a bunch of Digital Ocean droplets managed by Rancher. We use Gitlab for our Git hosting, and use Gitlab Pipelines for building our docker containers and deploying them to production.

The single line solution

In Slack, I checked with Bob to see what the easiest way was of getting the extensions installed when they're in the configuration but not in vendor/, and the solution was so simple I had not thought of it:

Run composer install --no-dev in your extensions/ directory

So I adapted my Dockerfile to include a single line:

RUN cd /var/www/extensions && composer install --no-dev

I committed the changes, pushed them, Gitlab picked them up and built the new container, Rancher pulled the new container and switched it on, and lo and behold, the extension was there!

(image)

Sometimes the simple solutions are actually the best solutions




Mocking at architectural boundaries: persistence and time - Matthias Noback

Tue, 20 Feb 2018 07:55:00 +0000

More and more I've come to realize that I've been mocking less and less. The thing is, creating test doubles is a very dangerous activity. For example, what I often see is something like this: $entityManager = $this->createMock(EntityManager::class); $entityManager->expects($this->once()) ->method('persist') ->with($object); $entityManager->expects($this->once()) ->method('flush') ->with($object); Or, what appears to be better, since we'd be mocking an interface instead of a concrete class: $entityManager = $this->createMock(ObjectManagerInterface::class); // ... To be very honest, there isn't a big different between these two examples. If this code is in, for example, a unit test for a repository class, we're not testing many of the aspects of the code that should have been tested instead. For example, by creating a test double for the EntityManager, we're assuming that it will work well with any objects we'll pass to it. If you've ever debugged an issue with an EntityManager, you know that this is a bad assumption. Anything may go wrong: a mistake in the mapping, missing configuration for cascading persist/delete behavior, an issue with the database credentials, availability of the database server, network connectivity, a missing or invalid database schema, etc. In short, a unit test like this doesn't add any value, except that it verifies correct execution of the code you wrote (something a linter or static analysis tool may be able to do as well). There's nothing in this test that ensures a correct working once the code has been deployed and is actually being used. The general rule to apply here is "Don't mock what you don't own" (see the excellent book "Growing Object-Oriented Software, Guided by Tests", or an article on the topic by Eric Smith, "That's Not Yours"). Whenever I've brought up this rule in discussions with developers, I've always met with resistance. "What else is there to mock?" "Isn't mocking meant to replace the slow, fragile stuff with something that is fast and stable?" Mock across architecturally significant boundaries Of course we want to use mocks for that. And we need to, since our test suite will become very slow and fragile if we don't do it. But we need to do it in the right place: at the boundaries of our application. My reasoning for "when to mock" is always: If you encounter the need for some information or some action that isn't available to you in the memory of the the currently running program, define an interface that represents your query (in case you need to know something) or command (in case you want to do something). Put the interface in the "core" of your application (in the domain or application layer). Use this interface anywhere you want to send this query or command. Write at least one implementation for the interface, and make sure all the clients of the interface get this implementation injected as constructor arguments. Mocking "persistence" To fix the EntityManager example above we need to take a step back and articulate our reason for using the EntityManager in the first place. Apparently, we were in need of persisting an object. This is not something the running application could do naturally (the moment it stops, it forgets about any object it has in memory). So we had to reach across the application's boundaries, to an external service called a "database". Because we always considering reusing things that are already available in our project, we just decided to go with the previously installed EntityManager to fulfill our needs. If however we would've followed the steps described above, we would've ended up in a different place: I need to persist (not just any object, but) my Article entity, so I define an interface that represents the action I intend for it to do: interface ArticleRepository { public function persist(Article $article): void } I use this interface everywhere in my code. I provide a default implementation for it, one that uses my beloved EntityManager: fin[...]



The Container is a Lie! - Nomad PHP

Sat, 17 Feb 2018 14:57:20 +0000

May - US
Presented By

Larry Garfield
May 17, 2018
20:00 CDT

The post The Container is a Lie! appeared first on Nomad PHP.




6 Things I Learned as an Exhibitor at SunshinePHP 2018 - Andrew Embler

Wed, 14 Feb 2018 13:51:00 +0000

(image)

Learn why bigger isn't always better.



Line Coverage in Unit Tests - Paul M. Jones

Tue, 13 Feb 2018 13:00:32 +0000

The novice says, “I do not strive for 100% line coverage in tests; I only write tests for the code that is important.”

The master says, “If the code is not important, why is it there at all? I will strive to test every line I write; if a line is not important, it should be removed.”

(See also The Way of Testivus.)




8 Tips for Improving Bootstrap Accessibility - SitePoint PHP

Mon, 12 Feb 2018 16:00:18 +0000

A few years ago, I wrote about my experiences on developing a Bootstrap version 3 project to be fully accessible for people with disabilities. This focussed mostly on how accessible it is in terms of front-end design. (It didn’t cover accessibility in terms of screen readers, as that’s a whole other story.)

While I could see that the developers behind Bootstrap were making an effort, there were a few areas where this popular UI library fell short. I could also see that there were issues raised on the project that showed they were actively improving — which is fantastic, considering how approximately 3.6% of websites use Bootstrap.

Recently, Bootstrap version 4 was released, so let’s take a look and see if any of the issues I had in the past have improved.

What We’re Looking For with Design Accessibility

There are a few things to consider when designing a website with accessibility in mind. I believe these improve the user experience for everyone and will likely cover a lot of points you would consider anyway.

Layout

One way to achieve accessibility is by having a clean, easy-to-use layout that looks good on all devices, as well as looking good at a high zoom level. Up to 200% is a good guide.

Bonus points: having front-end code that matches the layout is also good for users who access the Web with a screen reader or by using a keyboard instead of a mouse.

This allows people to use your website easily irrespective of how they’re viewing it.

Continue reading %8 Tips for Improving Bootstrap Accessibility%




Local and remote code coverage for Behat - Matthias Noback

Mon, 12 Feb 2018 08:48:00 +0000

Why code coverage for Behat? PHPUnit has built-in several options for generating code coverage data and reports. Behat doesn't. As Konstantin Kudryashov (@everzet) points out in an issue asking for code coverage options in Behat: Code coverage is controversial idea and code coverage for StoryBDD framework is just nonsense. If you're doing code testing with StoryBDD - you're doing it wrong. He's right I guess. The main issue is that StoryBDD isn't about code, so it doesn't make sense to calculate code coverage for it. Furthermore, the danger of collecting code coverage data and generating coverage reports is that people will start using it as a metric for code quality. And maybe they'll even set management targets based on coverage percentage. Anyway, that's not what this article is about... In my Advanced Application Testing workshop I just wanted to collect code coverage data to show how different types of tests (system, acceptance, integration and unit) touch different parts of the code. And how this evolves over time, when we're replacing parts of the system under test, or switch test types to achieve shorter feedback loops, etc. The main issue is that, when it comes to running our code, Behat does two things: it executes code in the same project, and/or (and this complicates the situation a bit) it remotely executes code when it's using Mink to talk to a web application running in another process. This means that if you want to have Behat coverage, you'll need to do two things: Collect local code coverage data. Instruct the remote web application to collect code coverage data itself, then fetch it. Behat extensions for code coverage For the workshop, I created two Behat extensions that do exactly this: LocalCodeCoverageExtension RemoteCodeCoverageExtension The second one makes use of an adapted version of the LiveCodeCoverage tool I published earlier. You have to enable these extensions in your behat.yml file: default: extensions: Behat\MinkExtension: # ... BehatLocalCodeCoverage\LocalCodeCoverageExtension: target_directory: '%paths.base%/var/coverage' BehatRemoteCodeCoverage\RemoteCodeCoverageExtension: target_directory: '%paths.base%/var/coverage' suites: acceptance: # ... local_coverage_enabled: true system: mink_session: default # ... remote_coverage_enabled: true Local coverage doesn't require any changes to the production code, but remote coverage does: you need to run a tool called RemoteCodeCoverage, and let it wrap your application/kernel in your web application's front controller (e.g. index.php): use LiveCodeCoverage\RemoteCodeCoverage; $shutDownCodeCoverage = RemoteCodeCoverage::bootstrap( (bool)getenv('CODE_COVERAGE_ENABLED'), sys_get_temp_dir(), __DIR__ . '/../phpunit.xml.dist' ); // Run your web application now... // This will save and store collected coverage data: $shutDownCodeCoverage(); From now on, a Behat run will generate a coverage file (.cov) in ./var/coverage for every suite that has coverage enabled (the name of the file is the name of the suite). The arguments passed to RemoteCodeCoverage::bootstrap() allow for some fine-tuning of its behavior: Provide your own logic to determine if code coverage should be enabled in the first place (this example uses an environment variable for that). This is important for security reasons. It helps you make sure that the production server won't expose any collected coverage data. Provide your own directory for storing the coverage data files. Provide the path to your own phpunit.xml(.dist) file. This file is used for its code coverage filter configuration. You can exclude vendor/ code for example. Combining coverage data froTruncated by Planet PHP, read more at the original (another 1457 b[...]



Deploy Docker containers fast to Microsoft Azure - Michelangelo van Dam

Sun, 11 Feb 2018 20:22:00 +0000

DEPLOY DOCKER CONTAINERS FAST TO MICROSOFT AZUREIt’s hard to ignore the fact that Docker is a way to move forward for rapid application development, distributed architectures and microservices.For developers Docker offers great advantages as they can build their containers specifically for the task they work on. They grab a base image of a container, modify it for their purpose and prepare the functionality inside the container.Quality, testing and security teams now have a single instance to look at and ensure all functional and regulatory requirements are met. System engineers now don’t have to worry about providing a system with the required specs as the container is already provisioned for that purpose.But where do you deploy your Docker containers? You can set up your existing bare metal infrastructure to allow them to run containers, but this also means you need to learn about securing your container infrastructure, which is not an easy task. Luckily “the cloud” offers container services like Google Cloud, RedHat OpenShift and Heroku. The most popular cloud solution providers are also stepping into the game of containers. Amazon Web Services offers Elastic Container Services that allows you deploy your Docker containers directly on their infrastructure.In this article I’m looking at how to deploy Docker containers on Truncated by Planet PHP, read more at the original (another 68625 bytes)[...]



ReactPHP with RecoilPHP: Creating for/http-middleware-psr15-adapter - Cees-Jan Kiewiet

Fri, 09 Feb 2018 00:00:00 +0000

There are more uses for coroutines than just making working with promises easier. In this post we're diving into the details on how they are used by the Friends of ReactPHP in the PSR-15 Middleware adapter for react/http.