Saturday, April 29, 2017

Upgrading Sylius the TDD Way: Exploring Behat

Last time, we developed some new features on top of Sylius' core to indicate which products and their variants are low on stock and need replenishing. Now, we move on to seeing our changes in the UI, which means we will need to do a bit of StoryBDD testing.

When browsing the list of products, we want to see a new column called Inventory which will hold a sum of all available tracked variants' stock amounts.


Sylius logo

Writing StoryBDD tests

Behat is the tool we want to use here. After making sure Behat is working well by running any feature from the Sylius package, we create a new features/product/managing_products/browsing_products_with_inventory.feature file with the following definition:

@managing_inventory
Feature: Browsing products with inventory
    In order to manage my shop merchandise
    As an Administrator
    I want to be able to browse products

    Background:
        Given the store operates on a single channel in "United States"
        And the store has a product "Kubus"
        And it comes in the following variations:
            | name          | price     |
            | Kubus Banana  | $2.00     |
            | Kubus Carrot  | $2.00     |
        And there are 3 units of "Kubus Banana" variant of product "Kubus" available in the inventory
        And there are 5 units of "Kubus Carrot" variant of product "Kubus" available in the inventory
        And I am logged in as an administrator

    @ui
    Scenario: Browsing defined products with inventory
        Given the "Kubus Banana" product variant is tracked by the inventory
        And the "Kubus Carrot" product variant is tracked by the inventory
        When I want to browse products
        Then I should see that the product "Kubus" has 8 on hand quantity

Again, we describe the make-up of our test product, stating the name, price and available stock of the two variants. If we run this feature, we see a list of paths for available contexts. We aren't interested in any of them, but we also get a hint, so we select None.

php bin/behat features/product/managing_products/browsing_products_with_inventory.feature

--- Use --snippets-for CLI option to generate snippets for following ui_managing_inventory suite steps:

    When I want to browse products
    Then I should see that the product "Kubus" has 18 on hand quantity

We create our context in src/Sylius/Behat/Context/Ui/Admin/ManagingProductsInventoryContext.php and add this:

<?php

// src/Sylius/Behat/Context/Ui/Admin/ManagingProductsInventoryContext.php

namespace Sylius\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;

class ManagingProductsInventoryContext implements Context
{
}

Running the feature again doesn't seem to help as we get the same list of contexts as before. That's because Sylius doesn't know anything about our class. We need to configure a service for our context together with what Sylius has in src/Sylius/Behat/Resources/config/services/contexts/ui.xml. We now search for managing_products and add this below it:

<service id="sylius.behat.context.ui.admin.managing_products_inventory" class="Sylius\Behat\Context\Ui\Admin\ManagingProductsInventoryContext">
    <argument type="service" id="sylius.behat.page.admin.product.index" />
    <tag name="fob.context_service" />
</service>

Let's add our sylius.behat.context.ui.admin.managing_products_inventory service (that's the id in ui.xml) to the context services for ui_managing_inventory suites in src/Sylius/Behat/Resources/config/suites/ui/inventory/managing_inventory.yml.

We may need to clear the cache. If we run the feature, we now get an option to select Sylius\Behat\Context\Ui\Admin\ManagingProductsInventoryContext. We then get:

--- Sylius\Behat\Context\Ui\Admin\ManagingProductsInventoryContext has missing steps. Define them with these snippets:

    /**
     * @When I want to browse products
     */
    public function iWantToBrowseProducts()
    {
        throw new PendingException();
    }

    /**
     * @Then I should see that the product :arg1 has :arg2 on hand quantity
     */
    public function iShouldSeeThatTheProductHasOnHandQuantity($arg1, $arg2)
    {
        throw new PendingException();
    }

We can just copy and paste the snippets into the context class we created. Out of curiosity we may import PendingException just to see the output. Let's add use Behat\Behat\Tester\Exception\PendingException; to the top of the class and re-run the feature.

We get an error:

An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'xxxx_test' (Doctrine\DBAL\Exception\ConnectionException)

That's because we haven't created the test database. These two commands will do that for us now.

Continue reading %Upgrading Sylius the TDD Way: Exploring Behat%


by Bruno Skvorc via SitePoint

New LinkedIn Remarketing Capabilities: This Week in Social Media

Welcome to our weekly edition of what’s hot in social media news. To help you stay up to date with social media, here are some of the news items that caught our attention. What’s New This Week LinkedIn Rolls Out Matched Audiences: LinkedIn introduced Matched Audiences, “a set of targeting capabilities that give you the [...]

This post New LinkedIn Remarketing Capabilities: This Week in Social Media first appeared on .
- Your Guide to the Social Media Jungle


by Grace Duffy via

Friday, April 28, 2017

Nahel Moussi - Portfolio

Portfolio of Nahel Moussi - French Interactive & motion designer
by via Awwwards - Sites of the day

100+ Facts and Stats About Instagram to be Aware of in 2017 (infographic)

Back in the year 2010, Instagram started as a photo-sharing app and crashed a lot but today it is helping businesses drive their growth and revenues. You must be wondering what has changed? The developers have continuously sought to nurture their app for people. Their addition of stories to...

[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Guest Author via Digital Information World

Goodbye Java Channel

As you can tell from the title, I’m writing to say goodbye – to you as well as to the Java channel. It is going on hiatus and this is the last newsletter that goes out. It was a great honor to be your editor! It gave me so many opportunities to interact with interesting […]

Continue reading %Goodbye Java Channel%


by Nicolai Parlog via SitePoint

Upgrading Sylius the TDD Way: Exploring PhpSpec

The post on developing and testing new Sylius features was an introduction to the three types of tests that are used in Sylius - PHPUnit, Phpspec and Behat.

In this part, we'll extend some core classes to indicate color-coded inventory status. First, we'll deal with the back end part. In a followup post, we'll use Behat and test the visual changes. Please follow the instructions in the previous post to get a working instance up and running.


Sylius logo

Sylius has an excellent inventory management solution. However, there's always some room for a tweak or two. If you look at the list of products (admin/products) there's no information about available stock. Looking at the variants of a product, we see inventory data, whether it's tracked or not, and the number of total items in stock, if tracked. It would be nice to see that kind of information on the product listing page, too. In addition, the stock level is all or nothing - for example, a green label says "10 Available on hand" or red "0 Available on hand". How about something in-between, say a yellow label for "3 Available on hand" to indicate that stock is low? Then, the store admin can decide it's time to replenish.

Extend ProductVariant and Product models

We want to extend the behavior of both the ProductVariant and Product models provided by Sylius, so we can see extra information on stock availability when viewing products.

Create a Bundle

First, we create the src/AppBundle/AppBundle.php file and register it in app/AppKernel.php.

<?php

// src/AppBundle/AppBundle.php

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppBundle extends Bundle
{
}

<?php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new AppBundle\AppBundle(),
    ];
}

Next, we inform the autoloader about the new bundle by adding it to the "autoload" section of composer.json.

Continue reading %Upgrading Sylius the TDD Way: Exploring PhpSpec%


by Deji Akala via SitePoint

#332: TypeScript 2.3 Released

This week's JavaScript newsRead this e-mail on the Web
JavaScript Weekly
Issue 332 — April 28, 2017
Redux is a popular library for managing state within JS apps, often used with React. This very thorough walkthrough covers how you’d build something similar.
Justin Deal

The JS superset includes a new comment-based type checking option, as well as support for async generators and iterators.
Microsoft

A frequently updated table of the proposals for future JS features along with their progress.
TC39

Bugsnag
Efficiently identify & resolve JavaScript errors affecting your users. Get alerted in real-time alongside detailed diagnostics, including stacktraces, plus support for sourcemaps. For a limited time, get a free t-shirt when you sign up & try Bugsnag.
Bugsnag   Sponsor

The first version with the new Ignition+Turbofan engines enabled by default, resulting in lower memory usage and faster speedup times. Will be used by Chrome 59 and Node 8.x.
Michael Hablich

A talk by Chris Heilmann of the Edge team covering the perennial topic of ‘fatigue’ over all the choices the JS ecosystem offers.
Chris Heilmann

A JS module that conjugates verbs and inflects nouns and adjectives, tell you what words are plurals or not, and more.
Alex Corvi

See how the exact same real world blogging platform is built using React or Angular on top of Node, Rails, and Django. Introductory blog post.
Thinkster

The team behind the V8 JavaScript engine want to know what proposed language features you’d like them to work on next.
Google

Jobs Supported by Hired.com

Can't find the right job? Want companies to apply to you? Try Hired.com.

In Brief

Angular 4.1: A Minor Release with Full TypeScript 2.2/2.3 Support news
Stephen Fluin

Ruby on Rails 5.1 Released, Embraces JavaScript news
The Ruby webapp framework is now a lot more JavaScript friendly.
David Heinemeier Hansson

☁️🥊 Hey Front-End Devs …Master Full Stack with Jem Young! 
Become a Full Stack Engineer and gain the confidence to master the command line and server.
Frontend Masters  Sponsor

How to Publish Packages on npm, A Video Series tutorial
Focuses on doing it the right way, complete with tests and docs.
Trevor Miller

Seven Tips for Handling 'undefined' tutorial
Dmitri Pavlutin

A Step-by-Step Guide to Building A Simple Chess AI tutorial
Lauri Hartikka

The Power of Custom Directives in Vue tutorial
Sarah Drasner

Build a Web Framework In Less Than 20 Lines Of Code tutorial
Everyday there are more new frameworks to learn, but it doesn't have to be that way!
PubNub  Sponsor

Does Glimmer Mean The Death of Ember? opinion
Robert Jackson

Why Is TypeScript Getting So Popular? opinion
Mary Branscombe

Callbacks vs Promises vs 'async/await' in a 7 Second Video video
Wassim Chegham on Twitter

Everything Is A Plugin: Mastering Webpack From The Inside Out video
An energetic, in-depth 100 minute talk/workshop.
Sean Larkin

Quokka: A Live JavaScript Scratchpad for JetBrains' IDEs tools
A month ago, this handy tool only worked with VS Code - now it supports JetBrains’ IDEs too :-)
Artem Govorov

Moon: A Minimal 5KB, Blazing Fast Vue-esque User Interface Library tools
Kabir Shah

p-event: Promisify An Event by Waiting for It to Be Emitted code
Sindre Sorhus

Slate: A Customizable Framework for Building Rich Text Editors code

angular-ssr: An Angular 4+ Server-Side Rendering Solution code
Christopher Bond

SmartPhoto.js: A Responsive Image Viewer, Especially for Mobile code

StrMan 2.0 Released: 66 Handy String Manipulation Functions code
Daniel Leite de Oliveira

Try Codeship Basic: simple hosted CI that works out of the box 
Codeship  Sponsor

Curated by Peter Cooper and published by Cooperpress.

Like this? You may also enjoy: FrontEnd Focus : Node Weekly : React Status

Stop getting JavaScript Weekly : Change email address : Read this issue on the Web

© Cooperpress Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via JavaScript Weekly