Create order during integration testing - integration-testing

For my custom integration test, I need some dummy order (I want to update the tracking number later, as per my module).
Until now the best was I found is to copy
\Shopware\Core\Checkout\Test\Order\Listener\OrderStateChangeEventListenerTest::createOrder to my test class. Is there a more convenient method, with less copy & paste?

There is a trait for getting valid OrderData. Then you can modify the data to your needs and create it with the OrderRepository.
You can find it here: src/Core/Checkout/Test/Customer/Rule/OrderFixture.php

Related

Is there any way to execute repeatable flyway scripts first?

We use flyway since years to maintain our DB scripts, and it does a wonderful job.
However there is one single situation where I am not really happy - possibly someone out there has a solution:
In order to reduce the number of scripts required (and also in order to keep overview about "where" our procedures are defined) I'd like to implement our functions/procedures in one script. Every time a procedure changes (or a new one is developed) this script shall be updated - repeatable scripts sound perfect for this purpose, but unfortunately they are not.
The drawback is, that a new procedure cannot be accessed by non-repeatable scripts, as repeatable scripts are executed last, so the procedure does not exist when the non-repeatable script executes.
I hoped I can control this by specifying different locations (e.g. loc_first containing the repeatables I want to be executed first, loc_normal for the standard scripts and the repeatables to be executed last).
Unfortunately the order of locations has no impact on execution order ;-(
What's the proper way to deal with this situation? Right now I need to specify the corresponding procedures in non-repeatable scripts, but that's exactly what I'd like to avoid ....
I found a workaround on my own: I'm using flyway directly with maven (the same would work in case you use the API of course). Each stage of my maven script has its own profile (specifiying URL etc.)
Now I create two profiles for every stage - so I have e.g. dev and devProcs.
The difference between these two maven profiles is, that the "[stage]Procs" profile operates on a different location (where only the repeatable scripts maintaining procedures are kept). Then I need to execute flyway twice - first with [stage]Procs then with [stage].
To me this looks a bit messy, but at least I can maintain my procedures in a repeatable script this way.
According to flyway docs, Repeatable migrations ALWAYS execute after versioned migration.
But, I guess, you can use Flyway callbacks. Looks like, beforeMigrate.sql callback is exactly what you need.

Saving API as environment variable (for setting up monkeylearn in R)

I would like to use the named entity recognition functions in the monkeylearn package in R.
As part of the setting up process, we need to do the following:
"To get an API key for MonkeyLearn, register at http://monkeylearn.com/. Note that MonkeyLearn supports registration through GitHub, which makes the registration process really easy. For ease of use, save your API key as an environment variable as described at http://stat545.com/bit003_api-key-env-var.html. You might also want to use the usethis::edit_r_environ() function to modify .Renviron.
All functions of the package will conveniently look for your API key using Sys.getenv("MONKEYLEARN_KEY") so if your API key is an environment variable called “MONKEYLEARN_KEY” you don’t need to input it manually.
Please also create a “MONKEYLEARN_PLAN” environment variable indicating whether your Monkeylearn plan is “free”, “team”, “business” or “custom”. If you do not indicate it by default it will be “free” with a message. If your plan is “custom” you’ll need a third environment variable “MONKEYLEARN_RATE” indicating the maximum amount of requests per minute that you can make to the API. If you do not indicate it, by default it will be 120 with a message."
I've gotten the API key, but as a layman, I couldn't understand the guide on saving the api key as environment variable. Could anyone provide a step by step guide for Windows please?
Thank you.
monkeylearn maintainer here, sorry for the unclear docs.
It means you need to add two lines in an R startup file called .Renviron.
MONKEYLEARN_KEY="blablablayourkey"
MONKEYLEARN_PLAN="free"
The last line of .Renviron has to be an empty line.
To open .Renviron to edit it, you can use usethis::edit_r_environ(). After adding the two lines with your key and plan, don't forget to restart R.
Read more about startup files in general in this resource.
I hope this helps. Note that I don't look up Stack Overflow very often as opposed to rOpenSci's forum

What is the use of DataLayer in Google Tag Manager

I am using Google Tag Manger; here I can pass dynamic values using “Javascript Vaiables”. Can anybody explain where will be the use of “dataLayer” ? I think, all of those dynamic value requirements can be done by using “Javascript variable” itself.
Thanks!
At least two things come to mind:
The Google Analytics transaction tracking requires a prefined dataLayer; that way you can use a simple tag template provided by Google instead of having to parse your own variable structure into something suitable
it largely avoids variable naming collisions with other scripts; you only need to check if another script or global variable also uses the variable name "dataLayer". With lots of 'simple' variables you'd have to check with each one if them for collisions
So yes, you do not have to use the dataLayer variable, but it's much more convenient and simpler to debug.
Further to Eike's answer, the dataLayer is a javascript variable :-)
The main point as I see it is that some of the user interface bits and pieces are designed to work with a "dataLayer" variable to make your life easier.
For example with some tags/tag templates you can just tell GTM to use values from the dataLayer directly; if you used javascript variables you'd need to manually define macros for each variable and manually assign them to a tag rather than just use the data directly from the data layer.

How to complete an existing phpunit test with a generator

PhpUnit has a generator of skel based on an existing class.
But it's works once.
If later some new method are added (because a dev doesnt work with tdd ), the test file is incomplete.
Is there a tool to generate a skel for uncovered method ?
I don't know any, and I also don't see the need. That skeleton generator generates one test method per function it finds, but you cannot test all use cases of a slightly advanced function within only one test function.
Also, the name of the test function is generated - but better names can and should be created to describe the intended test case or behavior of the tested function. Like "testGetQuoteFromStockMarket" vs. "testGettingMicrosoftQuoteFromStockMarketShouldReturnQuoteObject" and "testGettingUmbrellaCorporationFromStockMarketShouldFailWithException".
Note that you cannot test the throwing of exceptions in combination with cases that do not throw exceptions.
So all in all there simply is no use case to create "one test method per method" at all, and if you add new methods, it is your task to manually add the appropriate number of new tests for that - the generated code coverage statistics will tell you how well you did, or which functions are untested.
AFAIK there is no built-in phpunit functionality to updated the auto-generated test code; that is typical of most code generators.
The good news is that each of the functions is added quite cleanly and independently. So what I would do is rename your existing unit test file to *.old, regenerate a fresh test file, then use meld (or the visual diff tool of your choice) to merge in the new functions.
Aside: automatic test generation is really only needed at the start of a new class anyway; the idea of exactly one unit test per function is more about generating nice coverage stats to please your boss; from the point of view of building good software, some functions will need multiple tests, and some functions (getters and setters come to mind) do not really need any, and sometimes multiple functions are best covered by a single unit test (getters and setters again come to mind).

FLYWAY: How to maintain different sets of reference data for different environments

We are reviewing flyway as a replacement for Liquibase. However we have an existing database with a huge amount of reference data. As a result we would not always want to import the full set of reference data for all environments (for example development) - is there a standard way of using specific reference data for specific environment targets? Or is there an easy way of importing reference data outside of meta data using flyway?
thanks in advance
You can use multiple locations, configured differently per environment as described here: http://flywaydb.org/documentation/faq.html#db-specific-sql

Resources